Jump to content

Possible reasons that query to fails?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
hayschooler

hayschooler

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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?



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>";
  }
 
 
}


#2
technica

technica

    Learning Programmer

  • Members
  • PipPipPip
  • 63 posts
Have u checked if the books table has a foreign key? It might be linked with primary key in some other table.

#3
hayschooler

hayschooler

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
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?




#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
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?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
hayschooler

hayschooler

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Did you mean like this?

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.