本文介绍了获取当前时间/日期的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用PHP的简单代码,以使用TIMESTAMP获取当前的日期/时间,并将其插入数据库。
I need simple code using PHP to get the current date/time using TIMESTAMP and insert this into a database.
我在数据库中有一个名为ArrivalTime的字段作为TIMESTAMP。
I have a field called "ArrivalTime" within a database as TIMESTAMP.
编辑:
<?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("a&e", $con) or die('Could not select database.');//验证
$time = time(); $date = date('Y-m-d H:i:s',$time); $sql="INSERT INTO Patient(Forename, Surname, Gender, Date_Of_Birth, Address, Patient_History, Illness, Priority, Arrival_Time) VALUES('$patient_name', '$patient_lastname', '$gender', '$date', '$address', '$history', '$illness', '$priority', '$time')"; mysql_query($sql,$con) or die('Error: ' . mysql_error()); echo "1 record added"; // close connection mysql_close($con); ?>非常感谢
推荐答案main.php
<?php require('connect.php'); $time = time(); $sql = "INSERT INTO yourtablename (ArrivalTime) Values ('$time')"; mysql_query($sql); ?>PS:在sql语句中,我确定你需要把其他东西放在另一个字段,所以你只需要替换上面的一个:
P.S: in the sql statement i'm sure you'll need to put other things in the other fields ,so you just replace the one above by this:
$sql = "INSERT INTO yourtablename (field1, field2, ArrivalTime) Values ('$value1','$value2','$time')";connect.php
<?php $error = "Couldn't connect"; $connect = mysql_connect("localhost","username","password") or die($error); mysql_select_db("yourdatabase") or die($error); ?>更多推荐
获取当前时间/日期的时间戳
发布评论