Forum Moderators: open

Message Too Old, No Replies

MySQL Query works in PhpMyAdmin

...But Not When It Runs on a web page. Why?

         

jimh009

5:27 am on Jan 21, 2006 (gmt 0)

10+ Year Member



Hi,

I'm new to MySQL but am getting there. Here's a strange problem I'm having.

I create the MySQL queries in PhpMyAdmin, testing them off the actual database the site uses. This way I've found right away if things work or not. And so far, this method has worked perfectly.

However, tonight I have a problem.

I got this query to work in PhpMyAdmin. But when I put it into the web page as part of a script, it comes up with :

"Query was empty"

This is the actual SQL query that is working in PhpMyAdmin.

SELECT * FROM `table_name` WHERE productgroup = "product_group1" AND brand = "selected_brand" OR productgroup = "product_group2" AND brand = "selected_brand" ORDER BY rand() LIMIT 6

And this is the code I'm using for the query:

$sql = 'SELECT * FROM `table_name` WHERE productgroup = "product_group1" AND brand = "selected_brand" OR productgroup = "product_group2" AND brand = "selected_brand" ORDER BY rand() LIMIT 6';

Any ideas on what I'm doing wrong?

Thanks.

Jim

jimh009

6:03 am on Jan 21, 2006 (gmt 0)

10+ Year Member



Gee...so easy to make a mistake in MySQL

Just needed to substitute $query for $sql.

Those little programming things can just bug the heck out of you!

coopster

5:01 pm on Jan 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Actually, that would be the variable name in your scripting language there ... in this case PHP, not MySQL ;)

In any case, you are correct, you must make sure you are referring to the correct variable. Glad you got it sorted.