Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datetime value extracted from a Form 1

Status
Not open for further replies.

lupidol

Programmer
Apr 23, 2008
125
IL
Hi everyone,
My table ("list") contains one field ("exam_date") type: "datetime".
I want users to insert, via a Form, a value of datetime type so i can insert it into that table.
I want to display a default value in the input field: present date& time.
My code goes like this:
Code:
<!doctype html>
<html lang=en>
<head>
<title>Show Date</title>
<meta charset=utf-8>
</head>
<body>
<?php
$dbcon = @mysqli_connect ('xxx', 'xxx', 'xxx', 'xxx') 
	OR die ('Could not connect to MySQL: ' . mysqli_connect_error () ); 
mysqli_set_charset($dbcon, 'utf8');
if (isset($_POST['exam_date']))
{
$myDate = trim($_POST['exam_date']);
$q = "INSERT INTO list (exam_date) VALUES ($myDate)"; 
$result = @mysqli_query ($dbcon, $q); 	
?>
<form action="to_forum.php" method="post">
<input id="exam_date" name="exam_date" type="datetime" 
 value="<?php echo date(); ?>">
<input id="submit" type="submit" name="submit" value="Send">
</form>
</body>
</html>]
The above code doesn't show present date & time !
It adds a new row to my table but a blank date value ! no date added !
Can anyone show me the mistake i made in that code?
Thanks !
 
Code:
echo date('Y-m-d H:i:s');
remember that the default timezone must be preset in code or in the php.ini file.
the manual is an excellent place to start for this.
 
Thats very kind of you jpadie.
If I ever happen to take control of PHP->MySQL it will be thanks to you...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top