Page 1 of 1

Mysql query problems (very confused)

Posted: Sun Jun 11, 2006 7:45 pm
by rich86
Hi, i have been working with MySQL for a while now and made many database driven sites and always been able to fix any problems but this one is really bugging me.
I have a simple block of code that when working correctly should change an enabled value in a table to 0 but the query is not working. Here is the code:

Code: Select all

$find_pic_cat = sprintf("UPDATE pics_categories SET enabled=0 WHERE id=%s",
                                SQLValue($_POST['catid'],"int"));
$query_pic_cat = mysql_query($find_pic_cat);
SQLValue() is a function that i use on all the querys that makes sure eveything going into a database is valid. the "int" part tells it its an integer so it checks it is ok, the 0 does not go through this check as the function would return NULL, which is not what i wanted. Anyway when i run this nothing happens, so i added this part afterwards to debug:

Code: Select all

echo $find_pic_cat ."<br />".mysql_error($query_pic_cat)."<br />". mysql_info($query_pic_cat)."<br />".$_POST['catid'];
which returns:

Code: Select all

Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /home/bfp/public_html/class2005/user.php on line 361

Warning: mysql_info() expects parameter 1 to be resource, boolean given in /home/bfp/public_html/class2005/user.php on line 361
UPDATE pics_categories SET enabled=0 WHERE id=85


85
i have fun the query in phpMyAdmin and it works fine. i have even just put a simple "SELECT * FROM users" (another table that gets called before and works fine) in the mysql_query() function and i still get the same errors. I have tried changing all the variables, still same problem. I think that is the bulk of the info, if anything else is needed please ask.

Hope you can help many thanks

Richard

Posted: Sun Jun 11, 2006 8:27 pm
by bdlang
You're passing the $query_pic_cat value (a Resultset resource) to the mysql_error() and mysql_info() functions, both which expect a 'mysql link' resource (connection link).

Now, you're stating that the UPDATE actually does nothing? The column doesn't update?

I'd suggest changing the %s (string type) specifier to a %d or %u (int type) specifier in the sprintf() statement. Your SQLValue() function returns an INT type, correct?

If you don't mind, I'd like a look at your SQLValue() function, I have a similar function and class, I'm just curious what you've implemented. If you don't want to post to the general forum, please PM or email, thanks.

Posted: Mon Jun 12, 2006 5:43 am
by rich86
Opps, i have looked at it again this morning and i think it was an error else where in the code which was changing enabled back to 1 after it had been set to 0. thanks for your help anyway.