我已经整日忙于此事,还没有找到为什么不将其插入数据库的解决方案...它在本地工作正常,但在Web服务器上却没有,有人可以看看此代码,看看您是否可以看到错误或任何建议
欢呼
功能
public function Register($name, $email, $password)
{
try {
$db = DB();
$query = $db->prepare("INSERT INTO users(name, email, password) VALUES (:name,:email,:password)");
$query->bindParam("name", $name, PDO::PARAM_STR);
$query->bindParam("email", $email, PDO::PARAM_STR);
$enc_password = hash('sha256', $password);
$query->bindParam("password", $enc_password, PDO::PARAM_STR);
$query->execute();
return $db->lastInsertId();
} catch (PDOException $e) {
exit($e->getMessage());
}
}
这是我的注册脚本
$app = new SiteLib();
$register_error_message = '';
if (!empty($_POST['btnRegister'])) {
if ($_POST['name'] == "") {
$register_error_message = 'Name field is required!';
} else if ($_POST['email'] == "") {
$register_error_message = 'Email field is required!';
} else if ($_POST['password'] == "") {
$register_error_message = 'Password field is required!';
} else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$register_error_message = 'Invalid email address!';
} else if ($app->isEmail($_POST['email'])) {
$register_error_message = 'Email is already in use!';
} else {
$user_id = $app->Register($_POST['name'], $_POST['email'], $_POST['password']);
$_SESSION['user_id'] = $user_id;
header("Location:frontpage.php");
exit();
}
}
在此先感谢您的帮助
编辑:
这是错误
Warning: PDOStatement::setAttribute(): SQLSTATE[IM001]: Driver does not support this function: This driver doesn't support setting attributes in /customers/3/c/2/er.co.uk/httpd.www/lib/library.php on line 10 Warning: Cannot modify header information - headers already sent by (output started at /customers/3/c/2/er.co.uk/httpd.www/lib/library.php:10) in /customers/3/c/2/preptracker.co.uk/httpd.www/register.php on line 25
这是Library.php的第10行
$query->bindParam("name", $name, PDO::PARAM_STR);
这是Register.php的第25行
header("location:frontpage.php");
希望这会有所帮助