我正在尝试在 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.";
}