iNko Posted November 3, 2012 Share Posted November 3, 2012 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 More sharing options...
jazzman1 Posted November 3, 2012 Share Posted November 3, 2012 Show us other fields from the form and explain in clear English what do you want to do with this... Link to comment https://forums.phpfreaks.com/topic/270248-inserting-current-date-into-database/#findComment-1389938 Share on other sites More sharing options...
Pikachu2000 Posted November 3, 2012 Share Posted November 3, 2012 http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_curdate Link to comment https://forums.phpfreaks.com/topic/270248-inserting-current-date-into-database/#findComment-1389940 Share on other sites More sharing options...
iNko Posted November 3, 2012 Author Share Posted November 3, 2012 found an answer <input name="current_date" type="text" value="<?php echo date("Y-m-d"); ?>" readonly="readonly"/> writes currnet date to the text field, and when i press submit it writes it to the database.. Link to comment https://forums.phpfreaks.com/topic/270248-inserting-current-date-into-database/#findComment-1389941 Share on other sites More sharing options...
PFMaBiSmAd Posted November 3, 2012 Share Posted November 3, 2012 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. Link to comment https://forums.phpfreaks.com/topic/270248-inserting-current-date-into-database/#findComment-1389943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.