致命错误:对未定义函数mysql\u real\u escape\u string()html/phpmyadmin的未捕获错误调用

b1payxdu  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(285)

我目前库存:(基本上我正在做一个登录页面没有问题,但登录页面一旦我提交它。。。这是我登录页面的代码。

<form action= "process.php" method="POST">
Username: <input type="text" id="user" name="username">
Password: <input type="password" id="pass" name="password">
<input type="submit" value="Submit" >

但是现在我的process.php也犯了同样的错误。我似乎找不到问题所在。请帮忙这是密码

<?php
    $username = $_POST['user'];
    $password = $_POST['pass'];

    //to prevent sql injection
    $username = stripcslashes($username);
    $password = stripcslashes($password);
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string ($password);

    //connect to the server and select database
    mysql_connect("localhost","root","");
    mysql_select_db("franklin offshore");

    //query the database for user
    $result = mysql_query("select * from login where username='$username' 
    and password='$password'")
        or die ("Failed to query database ".mysql_error());
    $row = mysql_fetch_array($result);
    if ($row['username'] == $username && $row['password'] == $password)
    {
        echo "LOGIN SUCCESS WELCOME" .$row['username'];
    }
    else
    {
        echo "Failed to LOGIN" ;
    }
?>

这就是它一直在展示的东西
致命错误:未捕获错误:调用未定义函数mysql\u real\u escape\u string()
请帮忙

xu3bshqb

xu3bshqb1#

在下面尝试。。。会有用的。

<?php
$username = $_POST['user'];
$password = $_POST['pass'];

$username = stripcslashes($username);
$password = stripcslashes($password);

$db = mysqli_connect("localhost","root","","franklin offshore");

$result = mysqli_query($db, "select * from login where username = '$username' and password = '$password'")
                or die("Faild to query database " .mysqli_error());
$row = mysqli_fetch_array($result);
if ($row['username']== $username && $row['password'] == $password){
    echo "Login success!!! Welcome " .$row['username'];
} else {
    echo "Faild to login!";
}

?>

正如上面提到的,您需要在代码中用mysqli替换所有mysql。
使用php时请参考mysql与mysqli的链接
同时删除“mysql\u real\u escape\u string”代码。
谢谢您。

dkqlctbz

dkqlctbz2#

我建议使用 mysqli (替换 mysqlmysqli 并使用变量连接到数据库。
这样地:

$db = mysqli_connect("localhost", "username", "", "database");

那你得把 $db 在你的 mysqli_query 作为参数。
举个例子:

$result = mysqli_query($db, "select * from login where username='$username' and password='$password'");

相关问题