Jump to content

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


carlitoway

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

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'";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.