Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.