[英]how to write a php variable on a mysql query
我需要正确编写我的php变量。
$query2 = mysqli_query($con,"SELECT * FROM palettes LIMIT '$starting_number, $palettes_per_page'");
I don't think you want single quotes on your LIMIT parameters. 我认为您不希望在LIMIT参数上使用单引号。 One way is to use .
一种方法是使用。 to concatenate strings.
连接字符串。
Since $starting_number
and $palettes_per_page
are integers, you do not need to escape them. 由于
$starting_number
和$palettes_per_page
是整数,因此不需要转义它们。 If they were strings, wrap them in mysqli_real_escape_string
or mysqli_escape_string
to escape special characters. 如果它们是字符串,则将它们包装在
mysqli_real_escape_string
或mysqli_escape_string
以转义特殊字符。
$query2 = mysqli_query( $con,
"SELECT * FROM palettes LIMIT " .
$starting_number .
"," .
$palettes_per_page );
Just remove the single quote, because double quote can read variable's value 只需删除单引号,因为双引号可以读取变量的值
$query2 = mysqli_query($con,"SELECT * FROM palettes LIMIT $starting_number, $palettes_per_page");
Hope this works for you 希望这对你有用
您可以使用参数化查询,也可以避免使用mysqli_real_escape_string
$stmt = $conn->prepare("SELECT * FROM palettes LIMIT ?, ?'"); $stmt->bind_param("ii", $starting_number, $palettes_per_page); $stmt->execute();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.