elseif($_POST['delete']){
echo "<form name =\"delete\" action\"form4.php\" method=\"post\">";
echo "<input type=\"hidden\" name=\"isbn\"><br />";
echo "Are you sure you want to delete record?";
echo "<br />" . "<br />";
echo $_POST['isbn'] . '<br />' . $_POST['author'] . '<br />' . $_POST['title'] . '<br />' . $_POST['price'] . '<br />' . '<br />';
echo "<input type=\"submit\" name=\"yes\" value=\"Yes\">";
echo "<input type=\"submit\" name=\"no\" value=\"No\">";
echo "<br />" . "<br />";
echo "</form>";
echo"<a href=\"form4.php\">BACK</a>";
}elseif($_POST['yes']){
$query_3 = "DELETE * from books WHERE isbn ='$_POST[isbn]'";
$result_3 = mysql_query($query_3) or die ("Query 3 Failed!");
if($query_3){
echo "Delete Successful<br /><a href=\"form4.php\">BACK</a>";
}
}
Possible reasons that query to fails?
Started by hayschooler, Apr 20 2010 06:16 PM
4 replies to this topic
#1
Posted 20 April 2010 - 06:16 PM
I'm just trying delete a record from my database but the query fails. The message I get is that "Query 3 failed!". I'm not sure what to look at for possible reasons why the delete isn't successful. The delete statement syntax looks correct. I'm not sure what I've done wrong? What should I be looking for?
|
|
|
#2
Posted 20 April 2010 - 10:21 PM
Have u checked if the books table has a foreign key? It might be linked with primary key in some other table.
Programming Discussion :w00t:
#3
Posted 21 April 2010 - 07:06 AM
I checked and no there was no foreign shown when I describe books table.
I changed my query to
DELETE from books WHERE isbn = "'$_POST[isbn]'";
It made query successful but doesn't delete the record within the table?
I changed my query to
DELETE from books WHERE isbn = "'$_POST[isbn]'";
It made query successful but doesn't delete the record within the table?
#4
Posted 21 April 2010 - 07:11 AM
Often, I echo the SQL I'm trying to execute to the screen/webpage to ensure proper execution when testing. What's the actual SQL the database is getting?
#5
Posted 21 April 2010 - 08:39 AM
Did you mean like this?
It tells me that 0 rows were affected by the isbn selected and tried to delete.
**UPDATE**
Think I got it now, I wasn't including the value $_POST[isbn] in my input statement.
Thanks for your help.
It tells me that 0 rows were affected by the isbn selected and tried to delete.
echo "Status -- " . mysql_affected_rows() . " ISBNs updated<a href=\"form4.php\">BACK</a>";
**UPDATE**
Think I got it now, I wasn't including the value $_POST[isbn] in my input statement.
Thanks for your help.


Sign In
Create Account


Back to top









