【发布时间】:2017-05-10 21:28:35
【问题描述】:
我在 PHP 中有一个将值插入 MYSQL 表的函数。
function insertRow($db, $new_table, $ID, $Partner, $Merchant)
{
$insert = "INSERT INTO " .$new_table. " VALUES(number, "string", "string")"
$q = mysqli_query($db, $insert);
}
我正在努力自定义 VALUES 部分。我需要数字、字符串和字符串分别是 PHP 中的 ID、Partner 和 Merchant 变量。
我试过了
function insertRow($db, $new_table, $ID, $Partner, $Merchant)
{
$insert = "INSERT INTO " .$new_table. " VALUES(" .$ID . $Partner . $Merchant . ")";
$q = mysqli_query($db, $insert);
}
也是。但它似乎不起作用,因为对于 SQL,字符串值必须用引号括起来。但是,如果我更改代码,使其 ."$ID" 。 “$伙伴”。 “$商人”。 ")";因此变量根据需要放在引号中,它们不再是 PHP 变量。如何让我的 PHP 变量包含在引号中,以便正确执行 SQL?
【问题讨论】:
-
阅读数据库转义。