sách gpt4 ai đã đi

出现 PHP 错误但代码仍然正确执行

In lại 作者:太空宇宙 更新时间:2023-11-03 11:08:22 28 4
mua khóa gpt4 Nike

这个问题在这里已经有了答案:




9年前关闭。




Có thể trùng lặp:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select



运行此代码时出现两个错误:
include('config.php');
session_start();
$user_check=$_SESSION['login_user'];

$ses_sql=mysql_query("select username from admin where username='$user_check' ");

$row=mysql_fetch_array($ses_sql);

$login_session=$row['username'];

if(!isset($login_session))
{
header("Location: login.php");
}
?>

代码按我想要的方式执行,但抛出了这两个错误:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/jblanksb/public_html/lock.php on line 9


Warning: Cannot modify header information - headers already sent by (output started at /home/jblanksb/public_html/lock.php:9) in /home/jblanksb/public_html/lock.php on line 15

当我尝试使用 error_reporting(0); 隐藏错误时代码不起作用。

1 Câu trả lời

就在这条线之后

$ses_sql=mysql_query("select username from admin where username='$user_check' ");

Thêm vào
echo(mysql_error());

这将给出您实际遇到的错误。因为它目前给出了一个错误,所以它返回 FALSE,它是 bool 值(如输出所示。)
您的查询似乎是正确的,所以它的值可能是 $user_check你需要检查。

至于从/home/jblanksb/public_html/lock.php:9 开始的标题问题输出,您肯定会在 lock.php 的那一行输出一些东西。

http://php.net/manual/en/function.header.php

关于出现 PHP 错误但代码仍然正确执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10251997/

28 4 0