xx_princess_xx Posted May 9, 2009 Share Posted May 9, 2009 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); } ?> Quote Link to comment Share on other sites More sharing options...
RussellReal Posted May 9, 2009 Share Posted May 9, 2009 all the inputs are OUTSIDE of the form lol Quote Link to comment Share on other sites More sharing options...
xx_princess_xx Posted May 9, 2009 Author Share Posted May 9, 2009 sorry but that doesn't really help me Quote Link to comment Share on other sites More sharing options...
RussellReal Posted May 9, 2009 Share Posted May 9, 2009 // 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.