DATABASE SEARCH

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
Travelinman612
Forum Newbie
Posts: 4
Joined: Fri Feb 26, 2010 10:45 am

DATABASE SEARCH

Post by Travelinman612 »

ok I can connect to my database and pull info from it. I'm trying to search my database (using phpMyAdmin) in DB business, Table rest, and Field Cost. Im looking for "low" in that feild. When i run the code below it gives me this statement.

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 '\'Low\' LIMIT 0, 30' at line 1

$db_host = 'localhost';
$db_user = 'root';
$db_pass = 'blabla';
$db_db = 'business';
$db_table = 'rest';

$db_link = mysql_connect($db_host, $db_user, $db_pass)
or die('MySQl Connection Error:'.mysql_error());
mysql_select_db($db_db)
or die('MySQL Error: Cannot select table');
$XX = "No Record Found";
$query = "SELECT * FROM `rest` WHERE `Cost` LIKE \'Low\' LIMIT 0, 30 ";
$result = mysql_query("$query") or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);


while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo $row[Name] . " " . $row[Style];
echo "<br />";


}
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: DATABASE SEARCH

Post by AbraCadaver »

Why do you have slashes there? \'Low\'
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Travelinman612
Forum Newbie
Posts: 4
Joined: Fri Feb 26, 2010 10:45 am

Re: DATABASE SEARCH

Post by Travelinman612 »

cause i'm looking for "Low" in the field "cost"
Travelinman612
Forum Newbie
Posts: 4
Joined: Fri Feb 26, 2010 10:45 am

Re: DATABASE SEARCH

Post by Travelinman612 »

i got that string from phpmyadmin when I did a search on it and hit create php code. it gave me ---- $sql = "SELECT * FROM `rest` WHERE `Cost` LIKE \'low\' LIMIT 0, 30 ";
Kurby
Forum Commoner
Posts: 63
Joined: Tue Feb 23, 2010 10:51 am

Re: DATABASE SEARCH

Post by Kurby »

Travelinman612 wrote:i got that string from phpmyadmin when I did a search on it and hit create php code. it gave me ---- $sql = "SELECT * FROM `rest` WHERE `Cost` LIKE \'low\' LIMIT 0, 30 ";
Not sure why it put the \ in there, thats what is breaking it. Also, if your not using wildcard of any kind in your search statement than don't use LIKE. Just use

Code: Select all

SELECT * FROM `rest` WHERE `Cost` = 'low' LIMIT 0, 30
Travelinman612
Forum Newbie
Posts: 4
Joined: Fri Feb 26, 2010 10:45 am

Re: DATABASE SEARCH

Post by Travelinman612 »

Yeah it worked!!!!. Guess i was over complicating things!
Post Reply