-2

Hello i have this script.

if($_GET['page']) {
        if (isset($_GET['page']))
        $id = $db->escape_string($_GET['page']);
        if ($usersquery = $db->query("SELECT * FROM padges WHERE id ='$id' LIMIT 1"))
        $content = $usersquery->fetch_assoc();
    }
    if(!$_GET['page']) {
        if (isset($_GET['page']))
        $id = $db->escape_string($_GET['page']);
        if ($usersquery = $db->query("SELECT * FROM padges WHERE ID ='10' LIMIT 1"))
        $content = $usersquery->fetch_assoc();
    }

If i go to http://127.0.0.1/?page=10 i have no error. But if i go to http://127.0.0.1 i get this error.

Notice: Undefined index: page in /sites/ergotherapiewalcheren.nl/www/index.php on line 6 Notice: Undefined index: page in /sites/ergotherapiewalcheren.nl/www/index.php on line 12

How can i fix this error?

Tom Lammers

  • `if (isset($_GET['page']))` should check to see if `page` has been passed in. – andrewsi Oct 29 '15 at 22:40
  • Read about [$_GET](http://php.net/manual/en/reserved.variables.get.php) and [isset()](http://php.net/manual/en/function.isset.php) – Dan Oct 29 '15 at 22:40

1 Answers1

0

The first check should not be needed, remove:

if($_GET['page']) {

As you are already checking if it's set:

if (isset($_GET['page']))
taxicala
  • 21,408
  • 7
  • 37
  • 66