gpt4 book ai didi

php - mysql_num_rows() 根本不工作

转载 作者:行者123 更新时间:2023-11-30 23:55:10 25 4
gpt4 key购买 nike

我有这段 PHP 代码:

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

if($username&&$password){
$connect=mysql_connect("localhost","root","") or die(" Couldnt connect");
mysql_select_db("phplogin") or die ("Can't find database" .mysql_error());
$query=mysql_query("SELECT * users WHERE username='$username' ");
$numrows=mysql_num_rows($query);
if (!$query) {
die('Invalid query: ' . mysql_error());
}
}
else
die ("Enter username and password!") .mysql_error();
?>

但是,当我尝试运行这段代码时,出现了这些错误:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\PHP testing\login.php on line 9

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'users WHERE username='alex'' at line 1

有人可以向我解释我在这里做错了什么吗?

最佳答案

您必须使用 FROM 关键字指定要从中选择的表:

$query=mysql_query("SELECT * FROM users WHERE username='$username' ");
$numrows=mysql_num_rows($query);

关于php - mysql_num_rows() 根本不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6235528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com