Mysql query problems (very confused)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rich86
Forum Newbie
Posts: 15
Joined: Sun Jun 11, 2006 7:30 pm

Mysql query problems (very confused)

Post 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
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post 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.
rich86
Forum Newbie
Posts: 15
Joined: Sun Jun 11, 2006 7:30 pm

Post 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.
Post Reply