wildteen88 Posted June 5, 2011 Share Posted June 5, 2011 Not quite if(!$result) { echo 'error'; } else { // check that a record was deleted if(mysql_affected_rows() == 1) { echo 'Query deleted the record ' . $tID . ' successfully'; } // record was not deleted else { echo 'The query did not delete the record' . $tID; } } if(mysql_query($result,$conn)){ echo "$i encountered an error.<br/>"; } else { echo "$i successfully inserted.<br/>"; } That does need even relate to the OP's code. Quote Link to comment Share on other sites More sharing options...
lordshoa Posted June 5, 2011 Share Posted June 5, 2011 I am trying to help him write his own code not write it for him like you he wont learn from other people writing it for him. And how does it not relate ? only need to change the var to $tID Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 5, 2011 Share Posted June 5, 2011 all he is trying to do is get a good message when it has deleted not if it has deleted he knows its deleting it. So swapping the error message around would make a false positive a positive false. He did not say he wanted to know if it has deleted anything from the mysql just to get a good message when the right id is used. As he knows the rows are being deleted. if(mysql_query($result,$conn)){ echo "$i encountered an error.<br/>"; } else { echo "$i successfully inserted.<br/>"; } So what you're saying is that if the query executes without error, display an error message, and if the query fails to execute, display a success message? That's what that code does. A syntactically correct DELETE query with a non-existent id will execute successfully. The only way to tell if the query had the intended result of actually deleting a record is with mysql_affected_rows(). Quote Link to comment Share on other sites More sharing options...
lordshoa Posted June 5, 2011 Share Posted June 5, 2011 works for me if it looking at the false is correct but the code works then the error message is wrong so swapping them round would give the opposite effect yes ? As the CODE WORKS Quote Link to comment Share on other sites More sharing options...
bscyb Posted June 5, 2011 Author Share Posted June 5, 2011 Not quite if(!$result) { echo 'error'; } else { // check that a record was deleted if(mysql_affected_rows() == 1) { echo 'Query deleted the record ' . $tID . ' successfully'; } // record was not deleted else { echo 'The query did not delete the record' . $tID; } } if(mysql_query($result,$conn)){ echo "$i encountered an error.<br/>"; } else { echo "$i successfully inserted.<br/>"; } That does need even relate to the OP's code. ok this code fixed it all now i get the correct message when the record is deleted i get Query deleted the record and if the record is not deleted i get The query did not delete the record thanks allot Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 5, 2011 Share Posted June 5, 2011 works for me if it looking at the false is correct but the code works then the error message is wrong so swapping them round would give the opposite effect yes ? As the CODE WORKS A return of FALSE is not the correct result. FALSE means the query entirely failed to execute due to a syntax or other error, and the query could not possibly have deleted anything at all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.