我一直在寻找解决方案,但我找到的每一个似乎都没有用,我实际上并不确定是什么导致了这个问题。
如果我运行下面的mysql,这会将记录插入数据库。
INSERT INTO cust_v_lists (Customer_name, Customer_ref) VALUES ('wouldja', 133)
我的程序当前正在做的是使用第1页的参数创建上述语句,然后将mysql发布到第2页。在第2页,我的代码很简单。
$mysqli = $_POST['sqli'];
echo $mysqli; #this echo's out the above SQL insert line.
$result = mysqli_query($conn, $mysqli);
$updated = mysqli_affected_rows($conn);
$message = "You have inserted $updated row to the 'cust_v_lists' table.";
echo $message;
if (!mysqli_query($conn, $mysqli))
{
echo("Error description: " . mysqli_error($conn));
}
如果我硬编码如下:
$sqli = ;INSERT INTO cust_v_lists (Customer_name, Customer_ref) VALUES ('wouldja', 133)';
这很好用,但是当我发布它时我得到了错误
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
INSERT INTO cust_v_lists (Customer_name, Customer_ref) VALUES ('w' at line 1
我首先认为这是一个限制或40个字符的东西,但当我回应mysqli发布似乎没问题,我改变了php.ini的限制,以防万一,但这没有帮助。然后我使用$ mysqli =(string)$ mysqli将其更新为字符串,但这也没有帮助。谁看过这个吗?我不想硬编码,我需要查询从$ _POST完全动态和可读。
答案 0 :(得分:4)
$sqli = ;INSERT INTO cust_v_lists (Customer_name, Customer_ref) VALUES ('wouldja', 133)';
需要
$sqli = "INSERT INTO cust_v_lists (Customer_name, Customer_ref) VALUES ('wouldja', 133)";
答案 1 :(得分:1)
试试这个插入语句
$sqli = "INSERT INTO cust_v_lists (Customer_name, Customer_ref)
VALUES ('wouldja',133)";