简体   繁体   中英

how to get timestamp from user input(FORM) to its actual data?

let say I have a form:

<form ... >
<input type="text" name="date" /> //input here is 2013-06-14 09:00:00
</form>

I assigned it to let say:

$log = new record();
var_dump($log->timein = $_POST['date']); // OUTPUT is string(0) "" 

I tried using manual update:
var_dump($log->timein = '2013-06-14 09:00:00'); //string(19) "2013-06-14 06:00:00"

what will I do so that the $log->timein will get the value 2013-06-14 06:00:00 and not just empty strings?

if( isset($_POST['date']) && trim($_POST['date']) != '' ) {
  $log->timein = $_POST['date'];
} else {
  $log->timein = date('Y-m-d H:i:s');
}

I think you can just check for isset() and not empty() before declaring your variable

if(isset($_POST['date']) && !empty($_POST['date']))
{
      $log->timein = $_POST['date'];
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM