mysql_query和session,使用Login调用未定义的函数mysql_query()

When i execute my PHP code below i get a Fatal error and i'm not sure how to resolve it.

Thank you for your help

The Error

PHP Fatal error: Uncaught Error: Call to undefined function mysql_query() in /Applications/MAMP/htdocs/lprapp/config.php:23

Stack trace:#0 {main}

thrown in /Applications/MAMP/htdocs/lprapp/config.php on line 23

Code

$user = 'root';

$password = 'root';

$db = 'inventory';

$host = 'localhost';

$port = 8888;

$link = mysqli_init();

$success = mysqli_real_connect(

$link,

$host,

$user,

$password,

$db,

$port

);

?>

$username = $_POST['username'];

$password = $_POST['password'];

$sql = mysql_query("SELECT * FROM login WHERE username = '".$_POST['username']."' and password = '".md5($_POST['password'])."'");

$row = mysql_num_rows($sql);

if($rom > 0 )

{

session_start();

$_SESSION['username'] = $_POST['username'];

$_SESSION['password'] = $_POST['password'];

echo "login done";

}else {

echo "fail login ";

}

?>

解决方案

You are mixing mysql and mysqli

Change these lines:

$sql = mysql_query("SELECT * FROM login WHERE username = '".$_POST['username']."' and password = '".md5($_POST['password'])."'");

$row = mysql_num_rows($sql);

to

$sql = mysqli_query($success, "SELECT * FROM login WHERE username = '".$_POST['username']."' and password = '".md5($_POST['password'])."'");

$row = mysqli_num_rows($sql);

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值