Austin M-S Austin M-S - 4 months ago 8x
MySQL Question

Getting the date and sending it through mysqli insert?

Basically I've got a contact us form, and I would like to submit the date as well, when the submit button is pressed. Basically you fill out the boxes, submit, and the date goes through with it. I am just not sure exactly how to do it...

I've got the form in a .php in another page, but the action leads to the current page.

The date needs to be: year-mm-dd


include 'connection.php';

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$question = $_POST['question'];
$date = //I need the date here so it can go through the insert propperly;

if ($_POST['submit']){

mysqli_query($connect,"INSERT INTO contactusresults (`id`, `date`, `name`, `email`, `phone`, `question`) VALUES (NULL, '$date', '$name', '$email' , '$phone', '$question')") or die(mysql_error());

header('Location: ../pages/index.php');
//change to submit page
header('Location: ../pages/index.php');



Use php date function.

$date = date("Y-m-d H:i:s"); // If your mysql column is datetime
$date = date("Y-m-d"); // If your mysql column is just date

Use NOW() in sql

mysqli_query($connect,"INSERT INTO contactusresults (`id`, `date`, `name`, `email`, `phone`, `question`) 
VALUES (NULL, NOW(), '$name', '$email' , '$phone', '$question')") or die(mysql_error());