You can also try explicit variable notation in strings as follows:
$query = "SELECT * FROM table WHERE id = {$id}";
This allows you to do things like:
$name = "friend"; $str = "Hello {$name}s"; // Hello friends
where you could not do this if you tried:
$str = "Hello $names";
Since he will try to expand a variable named $ names.
Variables enclosed in single quotes are not expanded and are treated as literals, so "hey, $ id" will be exactly like that instead of the expected "hey, 1" if you used double quotes.
You can also try sprintf :
$query = sprintf("SELECT * FROM table WHERE id = %d", $id);
As the first poster said, definitely misinform your data before running queries.
typeoneerror
source share