Reputation: 839
$min_range=$_GET['min_range'];
$max_range=$_GET['max_range'];
$brand_name=$_GET['brand'];
$result=mysql_query(
"
SELECT
brand,
image,
price
FROM
mobile
WHERE
brand = '"$brand_name " 'price =3000
"
);
I want to use php variable in my sql query . What is wrong with this code. and how it can be corrected.
it is saying "parse error:syntax error,unexpect('$brand_name')"
Upvotes: 0
Views: 91
Reputation: 68466
Change your query to
$result=mysql_query("SELECT brand,image,price FROM mobile WHERE brand='$brand_name' AND price=3000");
You actually forgot to separate the condition. Added an AND
keyword.
Upvotes: 0
Reputation: 836
$result = $mysql->prepare("SELECT brand, image, price FROM mobile WHERE brand =? AND price=3000");
$result->bind_param($brand_name);
$result->execute();
Upvotes: 0
Reputation: 690
you can try this :
$result=mysql_query(
"
SELECT brand, image, price
FROM mobile
WHERE
brand = '" . $brand_name . "' AND price = 3000
");
Upvotes: 0
Reputation: 1
$result=mysql_query(
"
SELECT
brand,
image,
price
FROM
mobile
WHERE
brand = '.$brand_name.' AND price =3000
"
);
Upvotes: 0
Reputation: 1
$result = mysql_query("SELECT brand,image,price FROM mobile WHERE brand = '$brand_name' AND price = 3000");
Upvotes: 0
Reputation: 13511
One way is the following:
$result=mysql_query(
"
SELECT
brand,
image,
price
FROM
mobile
WHERE
brand = '" . $brand_name . "'
AND
price =3000
"
);
another way is this:
$result=mysql_query(
"
SELECT
brand,
image,
price
FROM
mobile
WHERE
brand = '$brand_name'
AND
price = 3000
"
);
Another way is this:
$result=mysql_query(
sprintf(
"
SELECT
brand,
image,
price
FROM
mobile
WHERE
brand = '%s'
AND
price = 3000
",
$brand_name
)
);
Also notice that your code, comes with syntax errors, replace the AND operator with one that meet your needs.
Upvotes: 1