开发者

Jquery datepicker defaultDate php isset check

开发者 https://www.devze.com 2023-03-25 15:57 出处:网络
I\'m coding a SQL query to look for events in a database. I use php to get the data from a html form and I\'m using different preset queries for various situations, one of which is:

I'm coding a SQL query to look for events in a database. I use php to get the data from a html form and I'm using different preset queries for various situations, one of which is:

  • the user didn't give a specific time using the jquery datep开发者_如何学编程icker; if so, I use php date() function to get today's date, and work with it; if not, I just use the from-to dates that the user selected.

Here's the problem: I'm using php to validate what the user gives as specific dates.

$fechaini = $_POST['fechaini'];
$fechafin = $_POST['fechafin'];
//cheking bars
if(isset($fechaini)){
     echo "fechaini: ".$fechaini;
   }
if(isset($fechafin)){
     echo "fechafin: ".$fechafin;
   }

This works fine but if the user didn't give any specific date (meaning he leaves it blank), php still echoes this output:

fechaini:
fechafin:

I need that if the user leaves the date inputs blank it prints nothing, allowing me to filter these inputs to build my queries without 'em.

Here is the site for you to see what happens: http://sistemahorarios.no-ip.org/sh/consultas4.php it will be avalaible for some time.


You may want to var_dump() the POST vars, I believe even if the user didn't select a date that field will still come back string(0) '', so I would do this to check:

 if('' !== $fechaini){
     echo "fechaini: ".$fechaini;
   }
   if('' !== $fechafin){
     echo "fechafin: ".$fechafin;
   }
0

精彩评论

暂无评论...
验证码 换一张
取 消