我正在尝试通过 MySQLi 将简单数据插入到我的 MySQL 表中,但是它拒绝插入,并且没有报告错误消息。
我想强调的是,当直接输入 PhpMyAdmin 时,此查询功能正常(当然,替换了变量)
<?php
session_start();
require_once('recaptchalib.php');
require_once('./inc/crypt.php');
require_once('./inc/mysql.php');
$privatekey = "-------------------------------- ";
$u = $mysqli->real_escape_string($_POST['username']);
$p = crypto($_POST['password']);
$e = $mysqli->real_escape_string($_POST['email']);
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$_SESSION['loginError'] = "The captcha was entered incorrectly!";
header("LOCATION: ./index.php?pg=1");
die();
}
$amt = 0;
if($data = $mysqli->prepare("SELECT * FROM users WHERE username=? OR email=?")){
$data->bind_param("ss", $u, $e);
$data->execute();
$data->store_result();
$amt = $data->num_rows();
$data->close();
}
if($amt != 0){
$_SESSION['loginError'] = "A user has already registered with either that email or username.";
header("LOCATION: ./index.php?pg=1");
die();
}
if(strlen($u) < 5){
$_SESSION['loginError'] = "A username must be greater than 5 characters long.";
header("LOCATION: ./index.php?pg=1");
die();
}
if(strlen($e) <= 5){
$_SESSION['loginError'] = "An email must be greater than 5 characters long.";
header("LOCATION: ./index.php?pg=1");
die();
}
if(!strstr($e, "@")){
$_SESSION['loginError'] = "A valid email must be entered.";
header("LOCATION: ./index.php?pg=1");
die();
}
if(!ctype_alnum($u)){
$_SESSION['loginError'] = "Your username contains an invalid character.";
header("LOCATION: ./index.php?pg=1");
die();
}
$ip = $_SERVER['REMOTE_ADDR']."r";
$mysqli->query("INSERT INTO users (`username`, `password`, `email`, `perms`, `ip`) VALUES ('".$u."', '".$p."', '".$e."', '0', '".$ip."')");
header("LOCATION: ./index.php?win=1");
?>
我还应该注意,同时使用 $mysqli->query 和准备好的语句都不起作用。
这是 MySQLi 部分下的我的 phpinfo() :
Client API library version 5.0.95
Client API header version 5.0.91
MYSQLI_SOCKET /var/lib/mysql/mysql.sock
Directive Local Value Master Value
mysqli.default_host no value no value
mysqli.default_port 3306 3306
mysqli.default_pw no value no value
mysqli.default_socket no value no value
mysqli.default_user no value no value
mysqli.max_links Unlimited Unlimited
mysqli.reconnect Off Off
最后一件事:我在另一个有效的文件中使用了一个非常相似的插入语句。
提前致谢