php if statements how to

So I've looked on various help sites but no one seems to be having the same problem as me, let me explain after my code:

    $pgint=$_POST['pg'];

    echo '<li><h4>Insects and Plants</h4>';
    switch($pgint)
    {
    case "1":
    echo '1';
    break;
    case "2":
    echo '2';
    break;
    }

It's not echoing anthing, even though "pg" is set to both 1 and 2. Can anyone help? The URL looks like: http://mydomainname.com/index.php?pg=1

not echoing anything. Can anyone help?

Upvotes: 0

Views: 46

Answers (2)

Phix
Phix

Reputation: 9920

In that case, pg is a GET variable, not POST.

Upvotes: 1

John Conde
John Conde

Reputation: 219934

You're confusing POST and GET. You need GET since the value you're looking for is in the querystring:

$pgint=$_POST['pg'];

should be:

$pgint=$_GET['pg'];

You should turn error_reporting() up to report all errors including notices. If you did you would have caught this immediately.

Upvotes: 10

Related Questions