Jump to content

Inserting Current Date Into Database


iNko

Recommended Posts

Got this code:

<label>Current date :</label>
<input name="current_date" type="date"/>


if(isset($_POST['submitted'])){
$error = FALSE;


if (empty($_POST['current_date'])) {
$error [] = 1;
} else {
$current_date= $_POST['current_date'];
}


if (!$error) {
$sqlinsert = "INSERT INTO Date (current_date)
VALUES ('$current_date')";
mysql_query($sqlinsert);
} else {

}
}

 

How do i make it so it automatically isert current date into the database?

Link to comment
https://forums.phpfreaks.com/topic/270248-inserting-current-date-into-database/
Share on other sites

Getting the date value through the form means that anyone can change it to anything (the readonly attribute WON'T actually stop anyone), so you must validate it and escape it before putting it into your query statement to prevent sql injection.

 

The value you put into your query should a value that is derived only on the server. See Pika's reply above on how you can do this directly in your query.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.