Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-26-2008, 06:35 AM php form error
Extreme Talker

Posts: 189
Trades: 0
there is an error in my code but I can find what it is, can anyone help me


PHP Code:
<?php
include("header.php"); 
?>
<td class="td" valign="top">



<?php

$name 
$_POST['name'];

$id explode("="$_POST['url']);

$no explode("|"$_POST['pet']);

if ( 
$_POST[submit] == yes ) {
if ( 
$_POST[name] <= ) {
  
$form 1;
    echo 
"You have to put a url in the box.<br>";
}
if ( 
$_POST[name] <= ) {
  
$form 1;
    echo 
"You have to put a name in the box.<br>";
}
if ( 
$_POST[pet] <= ) {
  
$form 1;
    echo 
"You have to choose a pet species.<br>";
}
else {

// Make a MySQL Connection
mysql_connect("mysql""jolyza""maddie") or die(mysql_error());
mysql_select_db("pettingpastures") or die(mysql_error());


mysql_query("INSERT INTO submissions (`id`, `name`, `no`, `img`) VALUES ('$id[1]', '$name', '$no[0]', '$no[1]');

echo 'Pet Submitted into Submissions file.';



}
}
if ( 
$form == 1 ) {
    echo '<br>';
    include 'form.txt';
}
else {
    include 'form.txt';
}
echo '</td>';


include 'footer.php';
 
?>
simster is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-26-2008, 07:12 AM Re: php form error
Average Talker

Posts: 28
Trades: 0
Remember that when you're using keys to specify an array item, you are using strings, not constants.

Change things like $_POST[name] to $_POST['name'].
Cory Dee is offline
Reply With Quote
View Public Profile
 
Old 05-26-2008, 08:49 AM Re: php form error
Extreme Talker

Posts: 189
Trades: 0
fixed

how do i get it to show my selected option in the drop down menu if the form is not fully compleated

form code
HTML Code:
To submit your pet to the Petting Zoo make sure its not all ready added, and then fill out this form and hit submit.<br><br>
<form method="post" action="submit.php">

<input type="hidden" name="submit" value="yes">

      Link to your Fluff Page:
    <input type="text" name="url" value="<?php if(isset($_POST['url'])) echo $_POST['url'];?>"><br>This will be something like http://apps.facebook.com/fluff/fluffbook.php?id=1109164160 .<br><br>
  Pets Name:
    <input type="text" name="name" value="<?php if(isset($_POST['name'])) echo $_POST['name'];?>"><br>
  Pet Species:  
  <select name="pet">
<option value="">Select Your Pet Species</option>
<?php
    $sortkey = '$name';

$fp = fopen('pets.txt','r');
if (!$fp) {echo 'ERROR'; exit;}

while (!feof($fp)) {
    $line = fgets($fp,2048); //use 2048 if very long lines
    $row++;
    list ($content, $name,$no) = split ('\/', $line);
    $col[$row] = array($sortkey, $name, $content, $no);
}

fclose($fp);

sort($col);
reset ($col);

$arrays = count($col) - 1;

$loop = -1;
while ($loop < $arrays) {
    $loop++;


if ($col[$loop][3] > "0") {

    echo '
<option value="'.$col[$loop][2].'">'.$col[$loop][1].'</option>';
}
}
?>
  </select>
<br>
<input type="submit" name="Submit" value="Submit" />
</form><br>
<i>Note: This will not add your pet to our database, we will add our submited (fluff)s to our database asap.</i>
simster is offline
Reply With Quote
View Public Profile
 
Old 05-28-2008, 07:25 AM Re: php form error
Average Talker

Posts: 28
Trades: 0
Without spending a ton of time figuring out your variable names, you're going to change this line to something like "if name is selected, mark it selected"

From:
echo '
<option value="'.$col[$loop][2].'">'.$col[$loop][1].'</option>';


To:
echo '<option value="' . $col[$loop][2] . '"';
if($col[$loop][2]==$_POST['pet'])
echo ' SELECTED';
echo '
>
'.$col[$loop][1].'</option>';
Cory Dee is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php form error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.49861 seconds with 12 queries