我是SQL的新手,所以我可能会遗漏一些东西。显然我在这一行有一个语法错误:
$mysql = 'INSERT INTO Orders (Name, Recipient, Destination, Room, Message, Anonymous, OffCampus, OffCampusAddress) VALUES (?, ?, ?, ?, ?, ?, ?, ?)';
有人能帮我辨别我做错了什么吗?提前致谢
错误:您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第1行“?,?,?,?,?,?,?,?)”附近使用正确的语法
这是我的参数绑定:
mysqli_stmt_bind_param($stmt, 'ssssssss', $name, $recipient, $destination, $room, $message, $anonymous, $offcampus, $offcampusaddress);
答案 0 :(得分:1)
它应该是这样的:
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');
$mysql = "INSERT INTO Orders\n" +
"(Name, Recipient, Destination, Room, Message, Anonymous, OffCampus, OffCampusAddress)\n" +
"VALUES\n" +
"(?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($link, $mysql);
mysqli_stmt_bind_param($stmt, 'ssssssss', $name, $recipient, $destination, $room, $message, $anonymous, $offcampus, $offcampusaddress);
mysqli_stmt_execute($stmt);
答案 1 :(得分:0)
尝试为列名添加`,为值添加'。它可能会起作用