这个问题在这里已经有答案了:
为什么我不应该在php中使用mysql函数(12个答案)
两年前关门了。
<?php
session_start();
$db = mysqli_connect("localhost","root", "", "authentication");
if (isset($_POST['regbtn'] )) {
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string($_POST['password']);
$password2 = mysql_real_escape_string($_POST['password2']);
if ($password == $password2) {
$password = md5($password);
$sql = "INSERT INTO users(username, email, password)
VALUES('$usrname','$email','$password')";
mysqli_query($db, $sql);
$_SESSION['message']="You are now logged in";
$_SESSION['username']= $username;
header("location: home.php");
}else{
$_SESSION['message']="The two passwords do not match";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Registration</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h1> Registration </h1>
</div>
<form method="post" action="register.php">
<table>
<tr>
<td> Username:</td>
<td><input type="text" name="username" class="textInput">
</td>
</tr>
<tr>
<td> Email:</td>
<td><input type="email" name="email" class="textInput"></td>
</tr>
<tr>
<td> Password:</td>
<td><input type="password" name="password" class="textInput">
</td>
</tr>
<tr>
<td> Confirm Password:</td>
<td><input type="password" name="password2"
class="textInput"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="regbtn" value="Register"></td>
</tr>
</table>
</form>
</body>
</html>
当我试图在xampp上运行它时,他们是这么说的:
致命错误:未捕获错误:调用c:\xampp\htdocs\authentication\register中未定义的函数mysql\u real\u escape\u string()。php:7 stack trace:#0{main}在第7行的c:\xampp\htdocs\authentication\register.php中抛出
因为7号线是: $username = mysql_real_escape_string($_POST['username']);
我想知道这里出了什么问题,我怎样才能找到解决这个问题的办法。谢谢您。
1条答案
按热度按时间xlpyo6sf1#
mysql从5.5开始就被弃用了:
自从php5.5以来,mysql扩展一直被弃用。应该改用mysqli或pdo扩展。在mysql\u deprevation中已经决定了这个决定,在这里可以找到关于这个决定背后原因的讨论。