我收到以下错误消息:致命错误:未捕获错误:在C:\ xampp \ htdocs \ mine \ server.php中调用未定义函数mysql_real_escape_string():12堆栈跟踪:#0 C:\ xampp \ htdocs \ mine \ _register.php(1):在第12行的C:\ xampp \ htdocs \ mine \ server.php中抛出include()#1 {main}
这是我的代码:
<?php
$username = "";
$email = "";
$errors = array();
//connect to the database
$db = mysqli_connect('localhost', 'root', '', 'registration');
//if the register button is clicked
if (isset($_POST['register'])) {
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$password_1 = mysql_real_escape_string($_POST['password_1']);
$password_2 = mysql_real_escape_string($_POST['password_2']);
//to ensure that the form fields are filled properly
if (empty($username)) {
array_push($errors, "Username is required");
}
if (empty($email)) {
array_push($errors, "Email is required");
}
if (empty($password_1)) {
array_push($errors, "Password is required");
}
if($password_1 != $password_2){
array_push($errors, "The two passwords do not match");
}
//if there's no errors, save the user to database
if(count($errors)==0) {
$password = md5($password_1); //encrypt password before storing to database (security)
$sql = "INSERT INTO users (username, email, password)
VALUES ('$username', '$email', 'password')";
mysqli_query($db,$sql);
}
}
?>