我的更新用户信息的代码:
if($update_stmt = $link_reg->prepare("UPDATE email_pass SET password=?, salt=?, customer_id=?, subscription_id=?, subscription_datetime=? WHERE email=?")){
$update_stmt->bind_param('ssssss', $new_password, $random_salt, $new_customer_id, $new_sub_id, $new_sub_datetime, $new_email);
if($update_stmt->errno){
echo($update_stmt->error);
}
// Execute prepared query
if($update_stmt->execute()){
// MORE CODE HERE
} else {
echo("ERROR?");
}
}
当我运行它时,我得不到反馈。我的数据表没有更新,但也没有echo
消息。
某处有错误吗?为什么代码不能正常执行?
这是一些示例UPDATE数据和表的列
$new_password = '532a69d8124604e33e9f45a8c9xbea92c342cbd5a3f847f770816dbd97975b2769f52a25806ead6100c1ac1a9a1a4de6b1641279a26854fba7c162caffca8e9f';
$random_salt = 'b6a1062d2c07c3aa900cbe9777d4670192f77241ad0b5ceb5f7968e3107f6d719b450d2ac37165e7827f53c2005797c985deddb9bec71724948bcd833ea72e87';
$new_customer_id = '19582601';
$new_sub_id = 'crj94x';
$new_sub_datetime = '2014-02-25 19:41:56';
$new_email = 'myemail@someemailplace.com';
CREATE TABLE
语法:
CREATE TABLE `email_pass` (
`row_id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`password` char(128) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`salt` char(128) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`customer_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`subscription_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`subscription_datetime` datetime NOT NULL,
PRIMARY KEY (`row_id`)
) ENGINE=MyISAM AUTO_INCREMENT=239 DEFAULT CHARSET=latin1
答案 0 :(得分:0)
我已经尝试过您的代码,但它确实有效。您的代码中有WHERE email=?
,其中填充了$new_email
。可能是因为您要通过搜索要设置的新电子邮件而不是当前的电子邮件地址(或where row_id = ...
)来查找要更新的记录?
即。您没有收到任何错误,也没有更新,因为您的email = <new email>
where子句没有匹配。
答案 1 :(得分:0)
Welp,事实证明我忘了向UPDATE
授予MySQL用户权限。它只能SELECT
和INSERT
。