darkenroyce Posted March 31, 2008 Share Posted March 31, 2008 Hi I want to use an input from a drop dialogue box which displays a list of user records from a column of in a MySQL table. When the users select the option they wish to delete they need to press the "submit button" labelled 'delete'. I have coded the drop down dialogue box but I can't the button to delete the record within the MySQL table. The code for the drop dialogue box is below: <td><select> <?php $conn = mysql_connect("localhost", "root") or die(mysql_error()); //database selected mysql_select_db("database", $conn) or die(mysql_error()); $state = "SELECT name FROM data"; $query = mysql_query($state, $conn); while($queryColumn = mysql_fetch_array($query)){ echo '<option value="' . $queryColumn ['name'] . '">' . $queryColumn ['name'] . '</option>'; } ?> I using the <form action = "filename" METHOD=POST></form> for this small form. The php file this redirects to runs this php code: <?php $con = mysql_connect("localhost","root") or die(mysql_error()); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql3 = "DELETE FROM data WHERE name VALUES ('$_POST[delete_data]')" mysql_query($sql3,$con); mysql_close($con); ?> delete_data refers to <input type="submit" name="delete_data" value="Delete"> Am I along the right tracks or completed wrong. This has been racking my brain for a while... Thanks Link to comment https://forums.phpfreaks.com/topic/98890-creating-a-delete-button-using-form-action-data-from-a-drop-dialogue-box/ Share on other sites More sharing options...
metrostars Posted March 31, 2008 Share Posted March 31, 2008 Hi I want to use an input from a drop dialogue box which displays a list of user records from a column of in a MySQL table. When the users select the option they wish to delete they need to press the "submit button" labelled 'delete'. I have coded the drop down dialogue box but I can't the button to delete the record within the MySQL table. The code for the drop dialogue box is below: <td><select> <?php $conn = mysql_connect("localhost", "root") or die(mysql_error()); //database selected mysql_select_db("database", $conn) or die(mysql_error()); $state = "SELECT name FROM data"; $query = mysql_query($state, $conn); while($queryColumn = mysql_fetch_array($query)){ echo '<option value="' . $queryColumn ['name'] . '">' . $queryColumn ['name'] . '</option>'; } ?> I using the <form action = "filename" METHOD=POST></form> for this small form. The php file this redirects to runs this php code: <?php $con = mysql_connect("localhost","root") or die(mysql_error()); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql3 = "DELETE FROM data WHERE name VALUES ('$_POST[delete_data]')" mysql_query($sql3,$con); mysql_close($con); ?> delete_data refers to <input type="submit" name="delete_data" value="Delete"> Am I along the right tracks or completed wrong. This has been racking my brain for a while... Thanks The only problem i can see is in the delete query. <?php $con = mysql_connect("localhost","root") or die(mysql_error()); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql3 = "DELETE FROM data WHERE name = '".$_POST[delete_data]."'" mysql_query($sql3,$con); mysql_close($con); ?> is what it should be. and also the button should be named submit, and the select drop down menu hould be named delete_data . Link to comment https://forums.phpfreaks.com/topic/98890-creating-a-delete-button-using-form-action-data-from-a-drop-dialogue-box/#findComment-506003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.