我已经用php MySQLi编写了查询,查询不会产生任何错误,虽然它没有做任何事情,这里是php代码
$db = SecureConnect(); //initialize connection
$stmt = $db->prepare("INSERT INTO `twitter_users`(`fullnames`, `email_address`, `password`, `twitter_id`, `twitter_username`, `screen_name`, `oauth_access_token`, `oauth_access_token_secret`, `PhoneNumber`, `dsate_created`) VALUES (?,?,?,?,?,?,?,?,?,?)"); ; //mysql statement
if ( false===$db ) {
die('prpe() failed: ' . htmlspecialchars($stmt->error));
}
$stmt->bind_param($names, $email, $password, $_POST['user_id'],$username, $_POST['screen_name'],$_POST['oauth_token'] , $_POST['oauth_token_secret'],$number, $date );
if ( false===$stmt ) {
die('bind() failed: ' . htmlspecialchars($stmt->error));
}
$stmt->execute();
if ( false===$stmt ) {
die('execute() failed: ' . htmlspecialchars($stmt->error));
}
$db->commit();
$stmt->close();
$db->close();
安全连接功能是正确的,因为我使用选择查询工作正常,我的代码有什么问题?
答案 0 :(得分:1)
我在阅读你的代码时注意到你的if语句是错误的。此外,IF语句的顺序应该重新排序。
$stmt
将为false bind_param()
将返回false
,而不会生成$stmt
实例false
。execute()
添加参数类型掩码' sssdssssds' //在上面的评论中提到
$db = SecureConnect(); //initialize connection
if ( false===$db ) {
die('connect() failed: ' . htmlspecialchars($db->error));
}
$stmt = $db->prepare("INSERT INTO `twitter_users`(`fullnames`, `email_address`, `password`, `twitter_id`, `twitter_username`, `screen_name`, `oauth_access_token`, `oauth_access_token_secret`, `PhoneNumber`, `dsate_created`) VALUES (?,?,?,?,?,?,?,?,?,?)"); ; //mysql statement
if ( false===$stmt ) {
die('prpe() failed: ' . htmlspecialchars($stmt->error));
}
$bind = $stmt->bind_param('sssdssssds', $names, $email, $password, $_POST['user_id'],$username, $_POST['screen_name'],$_POST['oauth_token'] , $_POST['oauth_token_secret'],$number, $date );
if ( false===$bind ) {
die('bind() failed: ' . htmlspecialchars($stmt->error));
}
if ( false===$stmt->execute() ) {
die('execute() failed: ' . htmlspecialchars($stmt->error));
}
$db->commit();
$stmt->close();
$db->close();