very lame problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Tue Apr 02, 2013 12:17 am

very lame problem

Postby shirley » Tue Apr 02, 2013 12:27 am

Okay guys Im a bit new in the community and I try to for dynamic navigation via mysql. When I use the code on my local server there are no issues, but when I upload it on my hosting account there is an error.

Here is the code:

Code: Select all

         $model = mysql_query("SELECT * FROM pages WHERE bmenu_id = {$brand["id"]}", $connection);
         if (!$model) {
            die("Database query failed: " . mysql_error());

The message I get from the server is: "Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"

I know this is probably something VERY stupid but I dont know how to handle it. :(!

Thanks in advance!

php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: very lame problem

Postby seandisanti » Tue Apr 02, 2013 8:55 am

1) To save yourself some trouble, build your query first, and then execute it like...

Code: Select all

"SELECT field1,field2 FROM table WHERE field =" $value;
$blah mysql_query($sql);

because then when it's not performing as expected, you can add 'die($sql)' to get just the query, which usually gives away the issue immediately, or at least gives you a query to run in phpMyAdmin or mysql.
In this case it would show you that using double quotes for your $brand key and your query doesn't work well.

2) mysql_ functions are deprecated and will probably be removed completely from a version in the very near future. PDO is a better way to interact with your database, and it's easy, I promise. check out this short video for a quick crash course ... o-examples

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 5 guests