rahish Posted March 25, 2006 Share Posted March 25, 2006 Hi I have a simple database which lists colours and displays them as background colours in a table.I also have a form on the page to insert new colours and another to delete a colour from the database.The delete form is not passing the correct strings to delete.php.The database is called test and it has fields id and colour.Here is the form[code]<h3>Delete colour</h3><form action="delete.php" method="get" id="submit"><select name='Colours'><?php$result = mysql_query($query) or die ("Couldn't execute query.");// Populate cells using a mysql_fetch_array script while ($row=mysql_fetch_array($result)){ $id=$row["id"]; $colour=$row["colour"]; //Populates a drop down menuecho "<option value='$id'id='$id'>$id $colour</option>";}?></select><input type="submit" name="submit" value="submit"><br></form>[/code] and here is the delete script in delete.php[code]<?phpinclude('admin/dbconnection.php');$delete=$_GET['submit'];$id=$_GET['id'];//$colour=$_GET['colour'];echo"$id";$delete=mysql_query("DELETE FROM boxes WHERE id=$id"); ?>[/code] Quote Link to comment Share on other sites More sharing options...
norman100 Posted March 25, 2006 Share Posted March 25, 2006 [!--quoteo(post=358171:date=Mar 25 2006, 02:53 AM:name=rahish)--][div class=\'quotetop\']QUOTE(rahish @ Mar 25 2006, 02:53 AM) [snapback]358171[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi I have a simple database which lists colours and displays them as background colours in a table.I also have a form on the page to insert new colours and another to delete a colour from the database.The delete form is not passing the correct strings to delete.php.The database is called test and it has fields id and colour.Here is the form[code]<h3>Delete colour</h3><form action="delete.php" method="get" id="submit"><select name='Colours'><?php$result = mysql_query($query) or die ("Couldn't execute query.");// Populate cells using a mysql_fetch_array script while ($row=mysql_fetch_array($result)){ $id=$row["id"]; $colour=$row["colour"]; //Populates a drop down menuecho "<option value='$id'id='$id'>$id $colour</option>";}?></select><input type="submit" name="submit" value="submit"><br></form>[/code] and here is the delete script in delete.php[code]<?phpinclude('admin/dbconnection.php');$delete=$_GET['submit'];$id=$_GET['id'];//$colour=$_GET['colour'];echo"$id";$delete=mysql_query("DELETE FROM boxes WHERE id=$id"); ?>[/code][/quote]I think its something to do with the way that you have printed your select box, try the following $result=mysql_query($query);print "<select name='YOURNAME' size=1>\n"; while ($row=mysql_fetch_row($result)) { print "<option value='$row[0]'>$row[0]\n"; }notes : Can be assigned to anything and will be the variable you collect on the next page ! $id = $_GET['YOURNAME'];Would hold your value Also for the drop down to display the colour dont change the option value but the second one like print "<option value='$row[0]'>$colour\n";That should work !!Nirmal Quote Link to comment Share on other sites More sharing options...
rahish Posted March 25, 2006 Author Share Posted March 25, 2006 Thanks for your help.I actually got it to work this wayI changed the id on the form to colour[code]<h3>Delete colour</h3><form action="delete.php" method="get" id="colour"><?php$result=mysql_query($query);echo "<select name='colour' size=1>\n";while ($row=mysql_fetch_array($result)){ $id=$row["id"]; $colour=$row["colour"];echo "<option value='$id'>$colour\n";}echo "</select>";echo "<input type='submit' name='submit' value='submit'>";?><br></form>[/code] and delete.php to this[code]<?phpinclude('admin/dbconnection.php');$delete=$_GET['submit'];$colour=$_GET['colour'];echo"$colour";$delete=mysql_query("DELETE FROM boxes WHERE id=$colour"); ?>[/code] Not quite sure why it worked but it deletes colours.Thanks againRahish[!--quoteo(post=358233:date=Mar 25 2006, 10:48 AM:name=norman100)--][div class=\'quotetop\']QUOTE(norman100 @ Mar 25 2006, 10:48 AM) [snapback]358233[/snapback][/div][div class=\'quotemain\'][!--quotec--]I think its something to do with the way that you have printed your select box, try the following $result=mysql_query($query);print "<select name='YOURNAME' size=1>\n"; while ($row=mysql_fetch_row($result)) { print "<option value='$row[0]'>$row[0]\n"; }notes : Can be assigned to anything and will be the variable you collect on the next page ! $id = $_GET['YOURNAME'];Would hold your value Also for the drop down to display the colour dont change the option value but the second one like print "<option value='$row[0]'>$colour\n";That should work !!Nirmal[/quote] 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.