我有一个包含 3 列的简单表格:
testID 是一个 INT(11) 自动递增的主索引
name 是一个 VARCHAR 文本字段
位置是一个 INT(11) 字段
<?php
error_reporting(E_ALL);
require("mysqli.test.inc");
$name1="Rhonda Hotop"; $position1=456;
$name2="Perry Shafran"; $position2 = 789;
$sqlupdate = "UPDATE test SET name = ?, position =?";
$sqlinsert = "INSERT INTO test (name, position) VALUES (name = ?, position = ?)";
//create the connection to the database
$con = new mysqli($hostname,$username,$password,$database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
//test an UPDATE
$statement = $con->prepare($sqlupdate);
$statement->bind_param("si", $name1, $position1);
$statement->execute();
$statement->close();
//test an INSERT
$statement = $con->prepare($sqlinsert);
$statement->bind_param('si', $name2, $position2);
$statement->execute();
$statement->close();
exit();
连接有效。
更新有效。
但是,INSERT 没有。它确实使用正确的 testID 字段创建了一条新记录,但 name2 和 position2 字段都设置为 0。
一些帮助将不胜感激。