问题描述:

i'm trying to make a simple login page in php, the code always echo "Sorry, your credentials are not valid, Please try again."...!! Please Help! :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.";

}

网友答案:
if(mysql_num_rows($result) == 1)

should be

if(mysqli_num_rows($result) == 1)

you can't mix and match mysql_ and mysqli_ functions.

相关阅读:
Top