我如何在php mysql上插入当前日期

时间:2016-05-02 07:19:38

标签: php mysql

我正在尝试插入当前日期,exp日期,25天间隔和电子邮件飞行日期,间隔为20天。但这些数据不会保存在数据库中。这可能是什么原因?

这是我的代码

//state open data
statesObj = {};
statesObj["StateCode"] = StateCode;
statesObj["CountryCode"] = CountryCode;
statesObj["StateName"] = StateName;
statesObj["CreatedBy"] = CreatedBy;
statesObj["CreatedOn"] = CreatedOn;
statesObj["ModifiedBy"] = ModifiedBy;
statesObj["ModifiedOn"] = ModifiedOn;
statesObj["Countries"] = CountrysObj;

2 个答案:

答案 0 :(得分:2)

如果您愿意,可以随时插入NOW()UTC_TIMESTAMP()

答案 1 :(得分:0)

试一试: -

<?php

include_once 'dbconnect.php';

if(isset($_POST['btn-signup']))
{
    $reqnum = $_POST['reqnum'];
    $Mnumber = $_POST['Mnumber'];
    $email = $_POST['email'];
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $emailErr = "Invalid email format";
    }

    $fname = $_POST['fname'];
    $address = $_POST['address'];
    $sitename = $_POST['sitename'];
    $payment = $_POST['payment'];
    $title = $_POST['title'];
    $descr = $_POST['descr'];
    $regdate = $_POST['reg_date'];
    $exp_date =$_POST['exp_date'];
    $emailflydate = $_POST['emailflydate'];

    //if()
    //{
    $new_fname= $_POST['sitename'];
    $xxx = mysql_query("SELECT sitename FROM gotest WHERE sitename = '$new_fname'")or die(mysql_error());
    $yyy = mysql_fetch_row($xxx);

    if(mysql_num_rows($xxx) > 0)
    {
        echo "<script type='text/javascript'>alert('gdrhh !')</script>";

    }
    else
    {
        $query = mysql_query("INSERT INTO gotest(Mnumber,email,fname,address,sitename,reqnum,payment,title,descr,reg_date,exp_date,emailflydate) VALUES('$Mnumber','$email','$fname','$address','$sitename','$reqnum','$payment','$title','$descr', '".date('Y-m-d h:i:s')."', '".date('Y-m-d h:i:s')."', INTERVAL 25 DAY ), DATE_ADD(CURDATE(), INTERVAL 20 DAY ))");

        $r = mysql_insert_id();


    }

}

?>