-1

I have categories in table I want to select data where category is Sales I am using following query

$query = mysql_query("SELECT * FROM catalog_Master where category=@"Sales"");
Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105

3 Answers3

1

Wrap it with single quotes because it is a string.

$query = mysql_query("SELECT * FROM catalog_Master where category='Sales'");

based on your comment, if you want the value from a variable,

$category="Sales";
$query = mysql_query("SELECT * FROM catalog_Master where category='$category'");

As a sidenote, the query is vulnerable with SQL Injection if the value(s) of the variables came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements you can get rid of using single quotes around values.

Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492
0

be careful with the double quotes, also if it's an exact match:

$query = mysql_query("SELECT * FROM catalog_Master where category='Sales'");

This should work

Naryl
  • 1,878
  • 1
  • 10
  • 12
0
<?PHP
$query = mysql_query("SELECT * FROM catalog_Master WHERE category='Sales'");
?>
**EDIT**

**PHP 5.5 way**

$mysqli = new mysqli("localhost", "db_user", "db_password", "db_name");
$result = $mysqli->query("SELECT * FROM catalog_Master WHERE category='Sales'");
Kevin G Flynn
  • 231
  • 4
  • 14