我的代码。
<?php //data.php require_once 'db.php'; // Get values from form $Fname = $_POST['first_name']; $Lname = $_POST['last_name']; $web = $_POST['web']; $email = $_POST['email']; $date = $_POST['date']; // Insert data into mysql $sql="INSERT INTO users (first_name, last_name, web, email, date) VALUES ('$Fname', '$Lname', '$web', '$email', '$date', NOW())"; $result = mysql_query($sql); $sql="SELECT DATE_ADD('$date', INTERVAL 30 day)"; $result = mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ header('Location: ../index.php'); } else { echo "ERROR"; } // close mysql mysql_close(); ?>
我的问题,当表单执行此文件时,我想将这30天添加到数据库的日期列中,然后在fname中插入fname,在web中插入web,并在日期+ 30间隔中插入日期。
谢谢你。
$sql="INSERT INTO users (first_name, last_name, web, email, date) VALUES ('$Fname', '$Lname', '$web', '$email', '$date', NOW())"; $result = mysql_query($sql); ***$sql="SELECT DATE_ADD('$date', INTERVAL 30 day)"; $result = mysql_query($sql);***
使用以下查询:
$sql="INSERT INTO users (first_name, last_name, web, email, date) VALUES ('$Fname', '$Lname', '$web', '$email',DATE_ADD('$date', INTERVAL 30 day) , NOW())";