1

I've got this code that should delete a row, containing a certain number from the database.

if ( isset($_POST['textfield_numtodelete']) )
{

$numToDel = $_POST['textfield_numtodelete'];

$resdel = mysqli_query( $con,"DELETE FROM pncall_numbers WHERE Number = '$numToDel'");

if ( $resdel ) { echo ("<center>".$numToDel." deleted successfully.</center>"); } else { echo("<center>".$numToDel." not found in database.</center>"); }

}

If successful, it should output "deleted successfully", else "not found in database". Yet $resdel always is true, even if I try to delete a number that's not there...

Thanks!

5
  • Please note that this is vulnerable to SQL injections. Furthermore, quoting a number isn't standard SQL. Commented Jul 3, 2011 at 13:30
  • As a side note you really need to escape the $numToDel parameter: $mysqli->real_escape_string($numToDel) Commented Jul 3, 2011 at 13:30
  • For $numToDel, you can also use intval(). That converts the string to an integer. Commented Jul 3, 2011 at 13:32
  • Also note that the center tag is deprecated. Commented Jul 3, 2011 at 13:42
  • Actually, he really should be using prepared statement. Commented Jul 3, 2011 at 14:32

1 Answer 1

3

true is returned because the query was successfully executed, even if no rows were deleted. Try mysqli->affected_rows after deletion

Sign up to request clarification or add additional context in comments.

1 Comment

Roger, if this answer helped you then please select this as "Answer".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.