【发布时间】:2014-04-26 18:22:54
【问题描述】:
我的代码不起作用。我正在使用 php 和 mysqli 建立登录网站。我包括准备好的声明以提高安全性,但我认为我做错了。请帮忙。
它无法将信息发送到数据库。
“准备失败!”出现。有什么问题??
<?php
if(isset($_POST['signup-name'], $_POST['signup-password-1'], $_POST['signup-password-2'], $_POST['signup-email-1'], $_POST['signup-email-2'], $_POST['signup-country'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'])){
if(!empty($_POST['signup-name']) and !empty($_POST['signup-password-1']) and !empty($_POST['signup-password-2']) and !empty($_POST['signup-email-1']) and !empty($_POST['signup-email-2']) and !empty($_POST['signup-country']) and !empty( $_POST['recaptcha_challenge_field']) and !empty( $_POST['recaptcha_response_field'])){
echo"ok";
$username = $_POST['signup-name'];
$password1 = $_POST['signup-password-1'];
$password2 = $_POST['signup-password-2'];
$email1 = $_POST['signup-email-1'];
$email2 = $_POST['signup-email-2'];
$country = $_POST['signup-country'];
//$recaptcha_challenge_field = $_POST['recaptcha_challenge_field'];
//$recaptcha_response_field = $_POST['recaptcha_response_field'];
if (filter_var($email1, FILTER_VALIDATE_EMAIL) && ($email1==$email2) && ($password1==$password2)) {
include 'db_info.php';
$mysqli = new mysqli("localhost", $db_uusseerrss, $db_ppwwdd, "user_db");
if (mysqli_connect_errno()) {
echo "no ok";
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "INSERT INTO user_info (`username`, `email`, `password`, `country`) VALUES( ?, ?, ?, ?)";
if ($stmt = $mysqli->prepare($query)) {
$stmt->bind_param('ssss', $username, $email1, $hashed_password, $country );
$stmt->execute();
$stmt->close();
//mysqli_close($link);
}else{
die('prepare() failed: ' . htmlspecialchars($stmt->error));
}
}else{
echo "filter failed!";
}
}else{
echo "value is not set";
}
}
}
?>
【问题讨论】:
标签: php sql mysqli prepared-statement