Burak Yücel
Burak Yücel

Reputation: 313

$_GET returns NULL when it's already not empty

I have a link like this: http://localhost/edit.php?id=0

But, When I try to take the value like this: $id = $_GET['id'];

It returns null. Why it's happening? My code is like this:

<?php
public function loadEdit($hconn) {
    if (!empty($_GET['id'])) {
        $id = $_GET['id'];
        if ($this->isNumber($id) != true && !($id > 0)) {
            echo $id;
            header("Location: /goods.php");
        } else {
            //header("Location: /goods.php");
        }
    }
}

Upvotes: 0

Views: 1798

Answers (2)

I recommend use:

if (array_key_exists('id', $_GET)) {

Upvotes: 0

Ian
Ian

Reputation: 25336

You're using if(!empty($_GET['id'])) { which will evaluate to false if $_GET['id'] has a value/string of zero.

Try using this instead:

if (isset($_GET['id'])) {

Upvotes: 3

Related Questions