Jump to content

[SOLVED] Testing if a query returned something


Kemik

Recommended Posts

Hello all,

 

I'm updating a row and checking if it worked. Please post your own version of the code if you feel this is over complicating it or just won't work at all.

 

<?php

$q = "UPDATE ".TBL_CLAN_MEMBERS." SET approve = '1' WHERE username = '$user'";
$result = mysql_query($q, $this->connection);
if(!$result || (mysql_affected_rows($result) < 1)){
     return NULL;
}

?>

 

The code updates the table as I want, however it then gives the following error:

 

  Quote
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/sh/public_html/ocwars/include/database.php on line 313

 

I've tried replacing mysql_affected_rows() with mysql_num_rows() but the same error occurs.

 

Then reference that connection in your mysql_affected_rows call.  If you're in the class, use the $this syntax, if your outside the class, and the connection is "public" you can reference it through the object...

 

$db = new database_connection();

.... code for query ....

echo mysql_affected_rows($db->connection);

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.