Jump to content

PHP using IF to display error


jay7981

Recommended Posts

i have a MySQL query and i want to display 1 thing only if the number of affected rows is >=1 and if not then display the error, here is what i have so far and nothing is being displayed ...

 

if (mysql_num_rows() >= "1")
{
echo "Update OK!<br />";
}
else	
{
die("Update failed: " . mysql_error());
}

Link to comment
https://forums.phpfreaks.com/topic/192590-php-using-if-to-display-error/
Share on other sites

Please forgive me as i am still learning,

 

this is my query, what i am trying to accomplish is

if the number of rows affected is >1

then echo Update OK!

and include ('ths_form.php')

 

if not then

echo Update failed: mysql_error()

and include ('that_form.php');

 

<?php
	$authid = "'" . mysql_real_escape_string($_POST['authid]') . "'";
	$name = "'" . mysql_real_escape_string($_POST['name']) . "'"; 
	$email = "'" . mysql_real_escape_string($_POST['email']) . "'";
	$fid = "'" . mysql_real_escape_string($_POST['fid']) . "'";
	$rank = "'" . mysql_real_escape_string($_POST['rank']) . "'";
	$access = "'" . mysql_real_escape_string($_POST['access']) . "'";
	$admin_id = "'" . mysql_real_escape_string($_POST['admin_id']) . "'";
	$group_id = "'" . mysql_real_escape_string($_POST['group_id']) . "'";

$query = "UPDATE bioclan.clan_members a INNER JOIN bioclan.admins b ON a.authid = b.auth INNER JOIN bioclan.sm_admins c ON a.authid = c.identity INNER JOIN bioclan.sm_groups d ON d.id = e.group_id INNER JOIN bioclan.sm_admins_groups e ON c.id = e.admin_id SET a.authid = $authid, a.name = $name, a.email = $email, a.fid = $fid, a.rank = $rank, b.auth = $authid, b.name = $name, b.access = $access, c.name = $name, c.identity = $authid, e.admin_id = $admin_id, e.group_id = $group_id WHERE a.authid = '" . mysql_real_escape_string($_POST['authid']) . "'";

mysql_query($query) or die("Query failed: " . mysql_error());

mysql_close($db);
?>

no it should only affect 1 row, does that make a difference?

 

if it affects more than 1 row i would like it to stop and not do anything except echo more than 1 row match your query

 

also would i replace this line with your code?

 

mysql_query($query) or die("Query failed: " . mysql_error());

It will have already executed the query though.

 

if ($result = mysql_query($query)) {
  if (mysql_affected_rows() > 1) {
    echo "More than one row updated";
  } else if (mysql_affected_rows() == 1) {
    echo "Update OK!";
  } else {
    echo "No rows updated";
  }
} else {
  echo "Query failed " . mysql_error();
}

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.