Id variable comes as empty in the url string

$id= $_GET['id'];

<li ><a href="prueba.php?id=<?php  $id   ?>"><img src="images/menu.gif" align="middle" alt="menu" width="100&#37;" height="22" /></a></li>

the link in the li tags will come out with an empty id in the url string like


Don’t know why is coming as empty.

<?php echo $id; ?>

Thank you very much Guido2004

even better

$id= (int) $_GET['id'];//type casting

so that you wont get any empty values, @ least 0

The “int” will force a value, but What about if not value is passed let’s suppose then what will be return?

Try this code:

$id = (int) $_GET['id'];
echo "prueba.php?id=".$id;

with empty $_GET[‘id’], $id will be equal to 0 due to type casting.

I’m actually surprised to see that converting from null to int is considered to be undefined behavior, even though it’s pretty widespread that people assume it should yield zero.