Default page die because of no value passed

hi,
I am having problem. when i load my page like content.php it will give me error of mysql statement because it didn’t got the id of the subject and die.but if i give value in url to variable it works. it means when the page is loaded when it doesn’t find any ID, it dies. here is the get id code i wrote.it has a clause which says if none then its empty. what am i doing wrong?


    if(isset($_GET['subj'])){
        $sel_subject = $_GET['subj'];
        $sel_page = "";
    }elseif(isset($_GET['page'])){
        $sel_page = $_GET['page'];
        $sel_subject = "";
        }else{
        $sel_subject = "";
        $sel_page = "";
        }
        $select_subject = get_subjects($sel_subject);

When $sel_subject = ‘’ the query is in your get_subjects query is not correct. See example 3 in my answer in your other thread: http://www.sitepoint.com/forums/showthread.php?859022-mysql_fetch_array()-expects-parameter-1-to-be-resource-boolean-given&p=5132219&viewfull=1#post5132219

This is another case where you could have seen the error yourself if you would have echoed out the query like we explained to you.

So you’ll have to decide what your script must do when there is no subject selected, and write the code for it. Just calling the get_subjects query as it is now without passing a subject id isn’t working, as you found out.

But i gave it selection that neither one is selected do nothing

No you didn’t.

Try identing your code a bit better, and you’ll see what is happening.


if (isset($_GET['subj'])) {
        $sel_subject = $_GET['subj'];
        $sel_page = "";
} elseif (isset($_GET['page'])) {
        $sel_page = $_GET['page'];
        $sel_subject = "";
} else {
        $sel_subject = "";
        $sel_page = "";
}
$select_subject = get_subjects($sel_subject);

You see? After the if-elseif-else has been finished, you always call the get_subjects function, even if you don’t have a subject_id.

i am no expert but i think should it be like this


        if(isset($select_subject)){
            $select_subject = get_subjects($sel_subject);
            $select_page = "";
        }elseif(isset($select_page)){
            $select_page =get_pages($sel_page);
            $select_subject = "";
        }else{
            $select_page = "";
            $select_subject = "";
        }

Moving the function call inside the if-elseif-else seems correct to me. But you’ve also changed all variable names in that piece of code. What happened to the old ones?

I was playing around to see what happens. that’s why

i was able to manage it and it worked but now when i click any link.when the other is not selected/clicked it gives out error saying
Notice: Uninitialized string offset: 0
suppose when i click pages.subjects gives me this error and also the other way around with subjects

I fixed the error. it was because i was telling saying “” if none is selected or either one. i made it to null and it worked