简体   繁体   中英

mysqli query() expects parameter 1 to be mysqli,

I use to run this code on the previous PHP version use to run fine currently, i am getting this error which is due to the new PHP version I tried to fix these issues as much as possible but still having these final 2 warnings that I don't know how to overcome will be thankful for the solution

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/u123456/public_html/sample/do_login.php on line 14

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/u123456/public_html/sample/do_login.php on line 15 Incorrect entry, Click here to go back

<?php
if(empty($_POST['user']) or empty($_POST['password']))
die("<center>User or Password is empty</br><a href=index.php>Click to go back</a></center>");
include('db.php');
session_start();
$uname= mysqli_real_escape_string($mysqlConnection, $_POST['user']); // using mysql_real_escape to protect against mysql injection
$pass=mysqli_real_escape_string ($mysqlConnection, md5($_POST['password'])); // using mysql_real_escape to protect against mysql injection
$code=$_POST['code'];


if ($code==$_SESSION["captchacode"])
{

$result = mysqli_query($uname, $pass, "SELECT * FROM user WHERE username='$uname' and password='$pass'");
if (mysqli_num_rows($result)>0)
{
$_SESSION['check']=1;
$row=mysqli_fetch_array($result);
$username2=$row['name'];
$_SESSION['name2']=$username2;

$type222=$row['type'];
$_SESSION['type2']=$type222;

$time22=$row['time_stamp'];
$_SESSION['time22']=$time22;

$un=$row['id'];
$_SESSION['un']=$un;


echo "<meta http-equiv='Refresh' content='1;url=main.php'>";
}

else
{
$_SESSION['check']="2";

echo "Incorrect entry, <a href=index.php>Click here</a> to go back";
}
}
else
echo "You did not input the code correctly, <a href=index.php>Click here</a> to go back and check your entry";

?>

I use to run this code on the previous PHP version use to run fine currently, i am getting this error which is due to the new PHP version I tried to fix these issues as much as possible but still having these final 2 warnings that I don't know how to overcome will be thankful for the solution

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/u123456/public_html/sample/do_login.php on line 14

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/u123456/public_html/sample/do_login.php on line 15 Incorrect entry, Click here to go back

<?php
if(empty($_POST['user']) or empty($_POST['password']))
die("<center>User or Password is empty</br><a href=index.php>Click to go back</a></center>");
include('db.php');
session_start();
$uname= mysqli_real_escape_string($mysqlConnection, $_POST['user']); // using mysql_real_escape to protect against mysql injection
$pass=mysqli_real_escape_string ($mysqlConnection, md5($_POST['password'])); // using mysql_real_escape to protect against mysql injection
$code=$_POST['code'];


if ($code==$_SESSION["captchacode"])
{

$result = mysqli_query($uname, $pass, "SELECT * FROM user WHERE username='$uname' and password='$pass'");
if (mysqli_num_rows($result)>0)
{
$_SESSION['check']=1;
$row=mysqli_fetch_array($result);
$username2=$row['name'];
$_SESSION['name2']=$username2;

$type222=$row['type'];
$_SESSION['type2']=$type222;

$time22=$row['time_stamp'];
$_SESSION['time22']=$time22;

$un=$row['id'];
$_SESSION['un']=$un;


echo "<meta http-equiv='Refresh' content='1;url=main.php'>";
}

else
{
$_SESSION['check']="2";

echo "Incorrect entry, <a href=index.php>Click here</a> to go back";
}
}
else
echo "You did not input the code correctly, <a href=index.php>Click here</a> to go back and check your entry";

?>

I use to run this code on the previous PHP version use to run fine currently, i am getting this error which is due to the new PHP version I tried to fix these issues as much as possible but still having these final 2 warnings that I don't know how to overcome will be thankful for the solution

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home/u123456/public_html/sample/do_login.php on line 14

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/u123456/public_html/sample/do_login.php on line 15 Incorrect entry, Click here to go back

<?php
if(empty($_POST['user']) or empty($_POST['password']))
die("<center>User or Password is empty</br><a href=index.php>Click to go back</a></center>");
include('db.php');
session_start();
$uname= mysqli_real_escape_string($mysqlConnection, $_POST['user']); // using mysql_real_escape to protect against mysql injection
$pass=mysqli_real_escape_string ($mysqlConnection, md5($_POST['password'])); // using mysql_real_escape to protect against mysql injection
$code=$_POST['code'];


if ($code==$_SESSION["captchacode"])
{

$result = mysqli_query($uname, $pass, "SELECT * FROM user WHERE username='$uname' and password='$pass'");
if (mysqli_num_rows($result)>0)
{
$_SESSION['check']=1;
$row=mysqli_fetch_array($result);
$username2=$row['name'];
$_SESSION['name2']=$username2;

$type222=$row['type'];
$_SESSION['type2']=$type222;

$time22=$row['time_stamp'];
$_SESSION['time22']=$time22;

$un=$row['id'];
$_SESSION['un']=$un;


echo "<meta http-equiv='Refresh' content='1;url=main.php'>";
}

else
{
$_SESSION['check']="2";

echo "Incorrect entry, <a href=index.php>Click here</a> to go back";
}
}
else
echo "You did not input the code correctly, <a href=index.php>Click here</a> to go back and check your entry";

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM