Hi all, this is my first time using this so i'm not really sure how it works. please bear with me.
i am trying to delete a row in a database using a select list. First of all i have a query to produce what i would like to be held in the select (dropdown) list. i then create the select list with a delete button. I then try to create the query to delete the selected option from the list from the database, but nothing happens and an error message appears. This error message however is not one of the error messages returned from one of my queries. Please Help!!!! what am i doing wrong?
<?php
$namequery = "SELECT DISTINCT projectnumber
FROM projects";
$result = mysql_query($na mequery) or die('Error, query failed');
$count = mysql_num_rows( $result);
if ($count > 0){
echo "<form action=\"<$self >\" method=\"post\" >";
echo "<select name=\"item\">" ;
while($result_r ow = mysql_fetch_arr ay($result)){
echo "<option name=\"item2\"> ";
echo ($result_row[0]);
echo "</option>";
}
echo "</select>";
echo "<input type=\"submit\" name=\"Delete\" id=\"Delete\" value=\"Delete\ " />";
if(isset($_POST['Delete'])){
foreach($_POST[item] as $del){
$query_delete = ("DELETE FROM projects WHERE projectnumber ='".$del."'") ;
$result = mysql_query($qu ery_delete) or die('Error, query failed');
}
echo "<meta http-equiv=\"refresh \" content=\"0\"; URL=\"AdminProj ects.php\">";
echo "Row deleted!";
}
echo "</form>";
}
else{
echo "There are no project numbers in the system";
}
?>
i am trying to delete a row in a database using a select list. First of all i have a query to produce what i would like to be held in the select (dropdown) list. i then create the select list with a delete button. I then try to create the query to delete the selected option from the list from the database, but nothing happens and an error message appears. This error message however is not one of the error messages returned from one of my queries. Please Help!!!! what am i doing wrong?
<?php
$namequery = "SELECT DISTINCT projectnumber
FROM projects";
$result = mysql_query($na mequery) or die('Error, query failed');
$count = mysql_num_rows( $result);
if ($count > 0){
echo "<form action=\"<$self >\" method=\"post\" >";
echo "<select name=\"item\">" ;
while($result_r ow = mysql_fetch_arr ay($result)){
echo "<option name=\"item2\"> ";
echo ($result_row[0]);
echo "</option>";
}
echo "</select>";
echo "<input type=\"submit\" name=\"Delete\" id=\"Delete\" value=\"Delete\ " />";
if(isset($_POST['Delete'])){
foreach($_POST[item] as $del){
$query_delete = ("DELETE FROM projects WHERE projectnumber ='".$del."'") ;
$result = mysql_query($qu ery_delete) or die('Error, query failed');
}
echo "<meta http-equiv=\"refresh \" content=\"0\"; URL=\"AdminProj ects.php\">";
echo "Row deleted!";
}
echo "</form>";
}
else{
echo "There are no project numbers in the system";
}
?>
Comment