Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test for successful MySQL delete

Status
Not open for further replies.

salewit

Programmer
Joined
Oct 31, 2002
Messages
58
Location
US
I got this straight out of my PHP book yet regardless of the value of $userid it ALWAYS comes out TRUE ($result=1). Is there a typo in my book? The code does work when the userid is correct.

$selstate = "DELETE from userdb WHERE username = '$userid'";
$result = mysql_query($selstate,$linkID);
if ($result == TRUE) {
print "<p>The record was successfully deleted.\n";
}
else {
print "<p>No such record with that UserID. Please check and try again.\n";
}
mysql_close($linkID);
 
echo "deleted ".mysql_affected_rows();

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
The reason why it comes out "TRUE" in all cases is that mysql_query() returns the sucessful execution of the the query, not if the query had any effect on the table. A successful query execution just means that there was no syntax error in the SQL statement.
It's concerning to see such misconceptions printed in instructional books.
 
Thanks for the replies. I actually *thought* this was a great book when I got it and started learning, but more and more I'm hearing people say things like "don't do it that way". This is a book by "Visual" FWIW.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top