Reputation: 313
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
Reputation: 2943
I recommend use:
if (array_key_exists('id', $_GET)) {
Upvotes: 0
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