View Full Version : POST, GET or EMPTY problem

08-04-2005, 07:03 PM
I have a site that every time I do any submit it reload itself and check what it has received. One of the variables I have to look for is the month selected by the user, something like this:

if (empty($_POST['Month'])) {
$mes = date("n")-1;
if (isset($_GET['mes'])){
$mes = $_GET['mes'];
else {
$mes = $_POST['Month'];
I do $mes = date("n")-1 because I use it in order to read an array.

The problem is that when January is selected, the variable Month (coming from a select in a form) is zero (0) and it is read as empty, so instead of taken the value in the else section, it gets into the if section (if empty).

If a variable is "0", then it is understood as an empty variable? :confused:

08-04-2005, 08:09 PM
Try using !isset() instead.

08-07-2005, 01:55 AM
Somewhere in the php site I read that one of the version of php says that empty('0')=true. I try using isset instead, but if the data is sent with submit button then isset( )=flase. So I send everything so that I just need the isset and never the empty.
I don't know if this is the best way, but I solved my problem.:rolleyes: