我是PHP和MySQL的新手。我的服务器具有MySQL 5.6版本。我正在使用过程性语句(不是PDO,不是OO)。这是我正在开发的网站上的PHP页面,供用户创建新帐户。奇怪的是,错误消息是在实际页面本身(https://mywebsite.com/create_account.php)上返回的,而不是在服务器上的错误日志中返回的。
*这是我收到的错误消息:*
错误:在用户中插入INSERT INTO用户(用户名,密码,name_first,name_last, 地址_1,地址_2,城市,州,邮政编码,电子邮件地址, phone_number,name_on_card,card_number_main,card_number_ccv, card_expire_mo,card_expire_yr)值(?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?),您的SQL语法有误;检查 与您的MySQL服务器版本相对应的手册 在'?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'附近使用的语法
*这是我的代码,它会生成错误消息:*
//
// Insert data into database
//
$sql = "INSERT INTO users (username, password, name_first, name_last, address_1, address_2, city, state, zip_code, email_address, phone_number, name_on_card, card_number_main, card_number_ccv, card_expire_mo, card_expire_yr) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($link, $sql);
mysqli_stmt_bind_param($stmt, "ssssssssssssssss", $param_username, $param_password, $param_name_first, $param_name_last, $param_address_1, $param_address_2, $param_city, $param_state, $param_zip_code, $param_email_address, $param_phone_number, $param_name_on_card, $param_card_number_main, $param_card_number_ccv, $param_card_expire_mo, $param_card_expire_yr);
$param_username = $username;
$param_password = $password;
$param_name_first = $name_first;
$param_name_last = $name_last;
$param_address_1 = $address_1;
$param_address_2 = $address_2;
$param_city = $city;
$param_state = $state;
$param_zip_code = $zip_code;
$param_email_address = $email_address;
$param_phone_number = $phone_number;
$param_name_on_card = $name_on_card;
$param_card_number_main = $card_number_main;
$param_card_number_ccv = $card_number_ccv;
$param_card_expire_mo = $card_expire_mo;
$param_card_expire_yr = $card_expire_yr;
mysqli_stmt_execute($stmt);
我已阅读该手册,但提示错误消息却无济于事。非常感激任何的帮助。谢谢。
答案 0 :(得分:-2)
在变量声明绑定stmt之后移动?
<?php
$sql = "INSERT INTO users (username, password, name_first, name_last, address_1, address_2, city, state, zip_code, email_address, phone_number, name_on_card, card_number_main, card_number_ccv, card_expire_mo, card_expire_yr) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($link, $sql);
$param_username = $username;
$param_password = $password;
$param_name_first = $name_first;
$param_name_last = $name_last;
$param_address_1 = $address_1;
$param_address_2 = $address_2;
$param_city = $city;
$param_state = $state;
$param_zip_code = $zip_code;
$param_email_address = $email_address;
$param_phone_number = $phone_number;
$param_name_on_card = $name_on_card;
$param_card_number_main = $card_number_main;
$param_card_number_ccv = $card_number_ccv;
$param_card_expire_mo = $card_expire_mo;
$param_card_expire_yr = $card_expire_yr;
mysqli_stmt_bind_param($stmt, "ssssssssssssssss", $param_username, $param_password, $param_name_first, $param_name_last, $param_address_1, $param_address_2, $param_city, $param_state, $param_zip_code, $param_email_address, $param_phone_number, $param_name_on_card, $param_card_number_main, $param_card_number_ccv, $param_card_expire_mo, $param_card_expire_yr);
mysqli_stmt_execute($stmt);