carlitoway Posted October 8, 2013 Share Posted October 8, 2013 Hi every one! here is my problem,my code works fine, if my two values(id, contrasena) are correct, then de row its eliminated and the message is "DELETE DATA SUCCESSFULY" but when one of this doesnt match it send me the same message! and i dont know how to do it for send other message like "Password or ID or email are invalid" <?php $id = $_POST["id"]; $contrasena = $_POST["contrasena"]; $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = "DELETE FROM provicional WHERE (id, contrasena) = ($id, '$contrasena')"; mysql_select_db('propiedades'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not delete data: ' . mysql_error()); } echo "Deleted data successfully\n"; mysql_close($conn); ?> Many thanks for you help...!! Quote Link to comment https://forums.phpfreaks.com/topic/282808-how-to-show-an-error-when-two-values-arent-equals-in-php/ Share on other sites More sharing options...
Solution winningdave Posted October 8, 2013 Solution Share Posted October 8, 2013 (edited) Hi. Carlitoway, At the moment you are just checking to see if the query has been executed and nothing to do with the result... I'd recommend the following <?php $id = $_POST["id"]; $contrasena = $_POST["contrasena"]; $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = "DELETE FROM provicional WHERE (id, contrasena) = ($id, '$contrasena')"; mysql_select_db('propiedades'); $retval = mysql_query( $sql, $conn ); //RETRIEVE THE NUMBER OF ROWS CHANGED IN THE PREVIOUS QUERY $affected = mysql_affected_rows($conn); if($affected!=1) { die('Could not delete data: ' . mysql_error()); } echo "Deleted data successfully\n"; mysql_close($conn); ?> You probably want to look at your query as well. Should be more along the lines of; $sql = "DELETE FROM provicional WHERE id='$id' AND contrasena = '$contrasena'"; Edited October 8, 2013 by winningdave Quote Link to comment https://forums.phpfreaks.com/topic/282808-how-to-show-an-error-when-two-values-arent-equals-in-php/#findComment-1453073 Share on other sites More sharing options...
carlitoway Posted October 8, 2013 Author Share Posted October 8, 2013 Thank you very much bro! its was more simple that i thought Quote Link to comment https://forums.phpfreaks.com/topic/282808-how-to-show-an-error-when-two-values-arent-equals-in-php/#findComment-1453093 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.