如何修复php中的未捕获/致命错误(由于调用未定义的函数)?

I'm trying to dabble with php instead of cgi when it comes to creating a login page for a website. Here's what I've come up with:

<?php
 $username = mysqli_connect("localhost", "$_POST['user']", ;  
 $password = $_POST['pass'];

 $username = stripcslashes($username);
 $password = stripcslashes($password);
 $username = mysql_real_escape_string($username,$_POST['user'] );
 $password = mysql_real_escape_string($password,$_POST['pass'] );

 mysqli_connect("localhost", "root", "");
 mysql_select_db("login");

 $result= mysql_query("select * from users 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!";
      }

?> 

I have received these errors upon compiling it with XAMPP Apache.

Notice: Undefined index: user in /opt/lampp/htdocs/process.php on line 2

Notice: Undefined index: pass in /opt/lampp/htdocs/process.php on line 3

Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in /opt/lampp/htdocs/process.php:7 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/process.php on line 7

It's my first time dabbling with php and i just followed a YouTube tutorial so I really don't know how to fix this error. Any help? Thanks.

dongxia8656
dongxia8656 我认为您需要在使用前检查是否设置了参数。if((__POST['username'])){现在为它赋值变量}
接近 4 年之前 回复
doushou7169
doushou7169 哦,你正在混合API。我们需要@Fred-ii-这里。
接近 4 年之前 回复
douhanzhuo6905
douhanzhuo6905 mysql_real_escape_string是一个内置函数,已被PHP7删除。该教程太旧了。
接近 4 年之前 回复
douao8353
douao8353 可能重复的PHP:“注意:未定义的变量”和“通知:未定义的索引”
接近 4 年之前 回复
doushang1964
doushang1964 丢弃你的教程,因为它已经完全过时了。现在没有人使用mysql扩展。
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐