-2

我正在尝试在 php 中创建一个简单的登录页面,代码总是回显“对不起,您的凭据无效,请重试。”...!!请帮忙!:D

    <?php 
error_reporting(0);

$user ='root';
$host = 'localhost';
$db = 'christcode';
$db_pass = '';

$con=mysqli_connect("$host","$user","$db_pass","$db");

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }else{

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


echo $username;
echo $password;
// Insert data into mysql 
$sql="SELECT * FROM users WHERE username='".$username."' and password='".$password."' limit 1";
$result = mysqli_query($sql);
echo $result;




if(mysql_num_rows($result) == 1)
    echo"You are a validated user.";
else
    echo"Sorry, your credentials are not valid, Please try again.";
}
4

1 回答 1

7
if(mysql_num_rows($result) == 1)

应该

if(mysqli_num_rows($result) == 1)

你不能混合和匹配 mysql_ 和 mysqli_ 函数。

于 2013-07-31T20:08:41.580 回答