Jump to content

Drop down list and form not working together


Recommended Posts

I have a drop down list for users to select an option which works

 

then i have a input form for users to send data

 

The problem is they are not working together

 

I would like users to select an option from the drop down list, then fill in the rest of the form and then submit, when i say they are not working together, i mean the form doesn't work with the drop down list the form won't submit

 

I am new at PHP so the layout is probalby quite bad,

<form action=<?php echo $_SERVER[ 'PHP_SELF']; ?> method="post">
<table border="0">
<tr>
<td>Agent ID</td>
<td>
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("comreg098hassan", $con);
  $result = mysql_query("SELECT AID FROM Agents");
  
  // start of form/menu
echo '<form>
<select name="aid">';

// produce the <option>'s
while($row_ID = mysql_fetch_array($result))
{
  echo '<option value="'.$row_ID['AID'].'">'.$row_ID['AID'].'</option>';
}

// end the menu/form
echo '</select>
</form>';
?>  
</td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="aname" value="<?php echo $aname; ?>" /> <?php if($errorID==1) echo "* $errorMsg"; ?></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" value="<?php echo $address; ?>" /> <?php if($errorID==2) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td>Post Code:</td>
<td><input type="text" name="post_code" value="<?php echo $post_code; ?>" /> <?php if($errorID==3) echo "*$errorMsg"; ?></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" /></td>
</tr>
</table>
</form>  
<?php
if(isset($errorID) && $errorID==0)
{
$con = mysql_connect("localhost", "root", "");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("comreg098hassan", $con);
$query = "UPDATE agents
SET aname='{$_POST[aname]}', address='{$_POST[address]}', post_code='{$_POST[post_code]}'
WHERE AID = '{$_POST[aid]}'";

$result = mysql_query($query) or die('Error: '.mysql_error()."\n".$query);
echo "1 record has been updated";
mysql_close($con);
}
?>

Link to comment
Share on other sites

// end the menu/form

echo '</select>

</form>';

 

you close the form there..

 

but all the inputs thereafter aren't INSIDE the form.. therefore, when you hit the submit button @ the end, ofcourse none of them are linked to the form.. close the formafter your submit button

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.