I need some PHP help! timestamp?

Status
Not open for further replies.
So this should be the insert into:

PHP:
$query = "INSERT INTO cmmnts2 (name, date, comment, email) " .
"VALUES ('$name', 'time()',  '$comment', '$email')";


Does the table stuff have to be in order?


And this should be the display?

PHP:
while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)) {
    echo '<b>Name:</b> '.$row['name'].'<br />
          <b>Comment:</b> '.$row['comment'].'<br />
          <b>Email:</b> ' .$row['email'].'<br />
          <b><i><font color="#393939">Date Posted:</b></i> '.date('M/d/Y h:i A', $row['date']).'<br /><br /></font>';
}

Ooo and im not sure if i used the font color the correct way..but it worked so oh well :) unless there is a better way..:p

With this code it still came out with the wrong date :/ Hmmph its probably somthing i did wrong :/
 
Try time() without the single quotes.

As for the order on the insert statement, if it is like this:
Code:
$query = "INSERT INTO cmmnts2 (name, date, comment, email) " . 
"VALUES ('$name', 'time()',  '$comment', '$email')";
then it is independant of the order of the fields in the table but if it is like this:
Code:
$query = "INSERT INTO cmmnts2 " . 
"VALUES ('$name', 'time()',  '$comment', '$email')";
then the values have to be in the same order as the fields in the table. You should ALWAYS use the first method.
 
PHP:
$query = "INSERT INTO cmmnts2 (name, date, comment, email) " .
"VALUES ('$name', '".time()."',  '$comment', '$email')";

Try this.
 
As just general guidance notes PHP as a reference library of all functions on its website, use this link: PHP Time (related to timestamp) to get the timestamp format you require (as the same with MySQL, uses the Unix timestamp generally but thats obviously on the Linux/Unix system, dont know too much about Windows, but dont like running apache on Windows, isnt really suited for it)
 
PHP still uses the UNIX timestamp on Windows. And you don't need Apache to use PHP on Windows, although Apache works absolutely fine on Windows.
 
Status
Not open for further replies.
Back
Top Bottom