Jump to content

How to show an error when two values arent equals in PHP


Go to solution Solved by winningdave,

Recommended Posts

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...!!

  • Solution

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 by winningdave
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.