scrtmtl
05-29-2011, 04:42 PM
Hi,,
Wondering what to use in the if condition for a date field in php when there is a form input involve?
Some background information:
1) Hacking a plugin to have a field of post expire. Myphpadmin shows field created with default assignment. Looks good.
if (!$exists) {
$h->db->query("ALTER TABLE " . TABLE_POSTS . " ADD post_expire DATE NOT NULL DEFAULT '2003-01-01' AFTER post_comments");
}
2) The program uses an input form and it allows the user to edit the input fields.
3) Var_dump (post_expire) of the date field is string(10) "0000-00-00"
4) The plugin was initially set to have a price field and I am trying to modify to have a date field. Modify the price field from float to int works but doing for date is the problem for me. The plugin uses if (!isset($price)) to assign a default price value.
Thus, my question is what to put in the if statement to test if date has a value cleanly (not to have the step 3 var dump value of 0000-00-00) and assign a DEFAULT '2003-01-01' if not define. Concern of null, 0 zeroes, spaces, and above var dump value.
Please note I try reading isset, empty, and posted this question for my concerns as a newbie to have the proper if condition. I will do a TESTDATE prior to inserting into db. Appreciate your help and tx.
Wondering what to use in the if condition for a date field in php when there is a form input involve?
Some background information:
1) Hacking a plugin to have a field of post expire. Myphpadmin shows field created with default assignment. Looks good.
if (!$exists) {
$h->db->query("ALTER TABLE " . TABLE_POSTS . " ADD post_expire DATE NOT NULL DEFAULT '2003-01-01' AFTER post_comments");
}
2) The program uses an input form and it allows the user to edit the input fields.
3) Var_dump (post_expire) of the date field is string(10) "0000-00-00"
4) The plugin was initially set to have a price field and I am trying to modify to have a date field. Modify the price field from float to int works but doing for date is the problem for me. The plugin uses if (!isset($price)) to assign a default price value.
Thus, my question is what to put in the if statement to test if date has a value cleanly (not to have the step 3 var dump value of 0000-00-00) and assign a DEFAULT '2003-01-01' if not define. Concern of null, 0 zeroes, spaces, and above var dump value.
Please note I try reading isset, empty, and posted this question for my concerns as a newbie to have the proper if condition. I will do a TESTDATE prior to inserting into db. Appreciate your help and tx.