Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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

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

PHP
$sql = "SELECT
            cat_id,
            cat_name,
            cat_description
        FROM
            duk_categories
        WHERE
            cat_id = '" . mysql_real_escape_string($_GET['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):

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

1 solution

You url query string is wrong, it should be:
/category.php?cat_id=2

You can use this to check the existence of query string
if (isset($_GET['cat_id'])){  
    // sql code here
} 
 
Share this answer
 
v2
Comments
jba1991 5-Jun-14 12:01pm    
I cant believe that. Sometimes I think I just shouldn't be doing web you know! Thanks a lot though. :)
Peter Leow 6-Jun-14 1:56am    
This is the inevitable part of the learning process, press on, never give up.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900