mysql affected rows

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

mysql affected rows

Post by ol4pr0 »

the following will always say the that the account has been activated.

Code: Select all

# sorry my mistake UPDATE table should be UPDATE users  


$query = mysql_query("UPDATE table SET unique_id='$_GET[id]',active=1 WHERE unique_id='$_GET[id]' AND active=0");
if(mysql_affected_rows()==1) {
//  if (mysql_affected_rows($query)==1) {
print 'you are activated';
}
else
{
print 'you are already activated or you have not been sent activation';    
}
I must be doing something wrong here
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Try this;

Code: Select all

<?php
mysql_connect($srv, $usr, $pwd) or die("Could not connect: " . mysql_error());
mysql_select_db($db);
$query = "UPDATE table SET unique_id='" . $_GET['id'] . "',active=1 WHERE unique_id='" . $_GET['id'] . "' AND active=0";
$result = mysql_query($query) or die("Could not query: " . mysql_error());
if (mysql_affected_rows($result) == 1)
	print 'you are activated';
else
	print 'you are already activated or you have not been sent activation';   
?>
-- Scorphus.
Post Reply