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:

 

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.

 

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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