PDA

View Full Version : PHP/MYSQL weird problem


Dave
11-23-04, 08:57 PM
I have been on this for a half hour, but I cannot figure out what the problem is...


<?
//DATABASE ACCESS
$db_username = "user";
$db_password = "pass";
$database = "db";
//CONNECT TO DATABASE
$link = mysql_connect("localhost",$db_username,$db_password);
if (!$link) {
die ("Could not connect to mySQL server.");
}
mysql_select_db($database);
if (!mysql_select_db ("$database", $link)) {
die ("Could not open database $database. " . mysql_error() );
}

if($_REQUEST['unsubscribe'] == "true"){

$sql = "UPDATE `newsletter` SET status = 'Inactive' WHERE id = '$_REQUEST[id]' AND email = '$_REQUEST[email]'";
$result = mysql_query($sql, $link);

if (!mysql_num_rows($result)) {
echo("<strong>There was an error deleting your email address form the database.</strong>");
}
else {
echo("<strong>Your email address has been deleted. You will no longer receive any mailings from us.</strong>");
}
}
?>


The actual query works, it does change the status to "Inactive," but then I get an error saying the following:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/domaing.com/httpsdocs/test.php on line 21

hobbestec
11-24-04, 08:34 AM
mysql_num_rows() will only return a value for a SELECT query, you need to use the mysql_affected_rows() function.

more info: http://us2.php.net/manual/en/function.mysql-affected-rows.php