get error in php, but goes fine in phpMyAdmin

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

get error in php, but goes fine in phpMyAdmin

Post by Sevengraff »

Ok, i'm getting a big headache from this.

Ok, im using a small template thing on my script. I keep the HTML for it in MySQL, and i use this query to get it out:

Code: Select all

SELECT value FROM sn_config WHERE name='skin'
Now, when I run something like

Code: Select all

mysql_fectch_object(mysql_query("SELECT value FROM sn_config WHERE name='skin'"))
i get

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource

However, I can run that same query in phpMyAdmin and not get any error at all. Plus, when i try to print mysql_error() or mysql_errno() nothing will be outputted.

I am extreamly confused. Why is it working in one place, and not another? I also am wondering why there is no error message from MySQL.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Instead of putting those two function calls together like:

Code: Select all

mysql_fectch_object(mysql_query("SELECT value FROM sn_config WHERE name='skin'"))
try separating them out and changing it to:

Code: Select all

$sql = "SELECT value FROM sn_config WHERE name='skin'";
$result = @mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
$row = mysql_fetch_object($result);
Mac
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

I tried that, and it gives me an error on the line with the mysql_fetch_object().
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What is the error you get?

Mac
praveen
Forum Newbie
Posts: 3
Joined: Thu Jan 23, 2003 5:34 am

Post by praveen »

you should give semi colon(;) at the end of the select statement.


mysql_fectch_object(mysql_query("SELECT value FROM sn_config WHERE name='skin'";));
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

I've found the problem. The class I was using to handel my sql stuff wasn't displaying mysql_error() correctly, and i wasn't connecting to the right database. thanks for your help, but it was just my fault.
Post Reply