未定义的索引问题 [英] Undefined Index problem

查看:93
本文介绍了未定义的索引问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我一直在试图绕过未定义的索引通知时遇到问题。



注意:未定义的索引:第13行的......中的cat_id



Hi,

Ive been having a problem trying to get around an Undefined Index notice.

Notice: Undefined index: cat_id in ...... on line 13

$sql = "SELECT
            cat_id,
            cat_name,
            cat_description
        FROM
            duk_categories
        WHERE
            cat_id = '" . mysql_real_escape_string($_GET['cat_id']) . "'";





这是通知中突出显示的代码。底线是第13行。我读到了关于isset但我仍然不确定如何做到这一点,任何帮助将不胜感激。



我通过了来自上一页的url(/category.php?2)中的cat_id是一个讨论板,用户可以在其中选择要查看的类别但该类别中的主题没有显示。



相反,这是正在执行的代码,告诉用户类别不存在(所以也不能有任何主题):





This is the code there is highlighted by the notice. the bottom line is line 13. I read about isset but I'm still not sure how to do it and any help would be greatly appreciated.

I am passing the cat_id in the url (/category.php?2) from the previous page which is a discussion board where the user can select which category they want to view but the topics inside that category arent being shown.

Instead, this is the code that is being executed which tells the user the category doesnt exist (so there cant be any topics either):

if(mysql_num_rows($result) == 0)
    {
        echo 'This category does not exist.';
    }

推荐答案

sql = SELECT
cat_id,
cat_name,
cat_description
FROM
duk_categories
WHERE
cat_id ='
。 mysql_real_escape_string(
sql = "SELECT cat_id, cat_name, cat_description FROM duk_categories WHERE cat_id = '" . mysql_real_escape_string(


_GET [' cat_id'])。 ';
_GET['cat_id']) . "'";





这是通知中突出显示的代码。底线是第13行。我读到了关于isset但我仍然不确定如何做到这一点,任何帮助将不胜感激。



我通过了来自上一页的url(/category.php?2)中的cat_id是一个讨论板,用户可以在其中选择要查看的类别但该类别中的主题没有显示。



相反,这是正在执行的代码,告诉用户类别不存在(所以也不能有任何主题):





This is the code there is highlighted by the notice. the bottom line is line 13. I read about isset but I'm still not sure how to do it and any help would be greatly appreciated.

I am passing the cat_id in the url (/category.php?2) from the previous page which is a discussion board where the user can select which category they want to view but the topics inside that category arent being shown.

Instead, this is the code that is being executed which tells the user the category doesnt exist (so there cant be any topics either):

if(mysql_num_rows(


result)== 0)
{
echo ' 此类别不存在。';
}
result) == 0) { echo 'This category does not exist.'; }


这篇关于未定义的索引问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆