-1

我在获取MySQL专栏时遇到了麻烦。mysql 中的所有内容都设置了用户名、密码、数据库、表

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given 
in /Applications/XAMPP/xamppfiles/htdocs/socialhut/login.php on line 8

这是 login.php 的代码:

<?php
$username = $_POST['username'];
$password = $_POST['password'];

$conn = mysqli_connect("localhost","root","","data");
$sql = "SELECT * FROM userdata WHERE username='$username' and password='$password'";
$query = mysql_query($sql);
$result = mysql_num_rows($query);

if ($result==1){
session_register($username);
session_register($password);
header('location:members.php');
}else{
mysql_error();
}
?>

任何人都可以弄清楚吗?谢谢!

4

1 回答 1

3

您正在使用相同的代码进行混合mysqlimysql调用。你不能那样做。

尝试这个:

$conn = mysqli_connect("localhost","root","","data");
$sql = "SELECT * FROM userdata WHERE username='$username' and password='$password'";
$query = mysqli_query($conn, $sql);
if ($query === false) {die(mysqli_error($conn));}
$result = mysqli_num_rows($query);
于 2013-08-30T02:29:31.387 回答