我的代码。
<?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);***
答案 0 :(得分:1)
这样做......
$sql="INSERT INTO `users` (`first_name`, `last_name`, `web`, `email`, `date`)
VALUES ('$Fname', '$Lname', '$web', '$email', DATE_ADD('$date', INTERVAL 30 DAY))";
答案 1 :(得分:1)
使用以下查询:
$sql="INSERT INTO users (first_name, last_name, web, email, date)
VALUES ('$Fname', '$Lname', '$web', '$email',DATE_ADD('$date', INTERVAL 30 day) , NOW())";
答案 2 :(得分:0)
试试这个:
$sql="INSERT INTO users (first_name, last_name, web, email, date)
VALUES ('$Fname', '$Lname', '$web', '$email', '$date', DATE_ADD(NOW(), INTERVAL 30 DAY))";
$result = mysql_query($sql);
>> you are adding date after query executes, but do the same when query executes.
由于
答案 3 :(得分:0)
以下是您需要更改的部分
$sql="INSERT INTO users (first_name, last_name, web, email, date)
VALUES ('$Fname', '$Lname', '$web', '$email', '$date', NOW() + INTERVAL 30 DAY)";