0

I was trying to get server's DATE with php, then pc's TIME with javascript and save them into my database. The problem is that I can store sever's date but not pc's time in my database. This is my database: jobs(id, date, time) . Structure type in my database for date set to DATE and for time set TIME Any idea what the problem might be? This is my code:

<?php

// get sever's date

$server_date = date('Y.m.d');

// get pc's time 

$pc_time='
<script language="javascript">
var today = new Date();
today = today.getHours() + ":" + today.getMinutes()+":" + today.getSeconds();
document.write(today);
</script>';

mysql_query("INSERT INTO `jobs` VALUES ('', '$server_date ', '$pc_time')   "); 

?>

I can succesfully store server's date but not the time.

l2aelba
  • 21,591
  • 22
  • 102
  • 138
user2491321
  • 673
  • 10
  • 32

1 Answers1

2

You're close. But the server-side script won't be able to execute that JavaScript. In other words, your PHP variable won't even be populated until after the script has run, and you've already run your INSERT.

Take that same idea, but populate a form field, and submit that to your page. Grab it with a $_POST in PHP, and submit that.

durbnpoisn
  • 4,666
  • 2
  • 16
  • 30