Reputation:
I am unable to execute query
if (!mysql_query("SELECT `title`,LEFT(`description`,70) as `description`,`url`
FROM `articles`
WHERE `keywords` LIKE '%blog%'"))
{
echo 'Failed';
}
If I copy and run the same query directly into SQL menu of localhost, it runs successfully.
Upvotes: 1
Views: 269
Reputation: 37233
why not using this
$sql = mysql_query("SELECT `title`,LEFT(`description`,70) as `description`,`url`
FROM `articles`
WHERE `keywords` LIKE '%blog%'") or die (mysql_error());
//^^^^^^^^^^^^^^^---better use this instead of "failed" to debug, if want change it do it like that **or die ('failed');**
it works like the if ,it will be interpreted like that :
execute my query please or if its not true my query please die and echo the error.
This cant be used in production but only during development for not passing technical error messages to the user, can give them important hints on detecting and/or exploiting vulnerabilities
Upvotes: 1
Reputation: 22166
Perhaps your MySQL connection is not setup well. Is your mysql_connect($db_host, $db_user, $db_pass)
ok? Have you selected the right database using mysql_select_db()
?
Upvotes: 0