Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
<?php //Booking Request index file that sends data from the form to the database 
		
		include 'connection.php';	
		
		// Assigning Variables
		
		$evename = $_POST['event_name'];
		$evedescrip = $_POST['event_description'];
		$evetype = $_POST['event_type'];
		$fac = $_POST['name_of_facility'];
		$startdate = $_POST['event_start_date_time'];
		$enddate = $_POST['event_end_date_time'];
		$evecood = $_POST['event_coordinator'];
		$bookdate = date('d-m-y');
		 
		
		// Variable that executes request to send data to database
		$sql = "INSERT INTO booking_requests (`event_name`,`event_description`,`event_type`,
		`name_of_facility`,`event_start_date_time`,`event_end_date_time`,`event_coordinator`,`booking_request_date`)
				VALUES('$evename','$evedescrip','$evetype','$fac','$startdate','$enddate','$evecood',$bookdate)";

		// Statement stating whether the execution is successful
		if (!mysqli_query ($link,$sql)){
		die ('Error: ' . mysqli_error($link));
		} 
		else 
		echo ('Entry successfully submitted');
?>


The variable $bookdate does input into the database but it inputs like 0000-00-00. Whats wrong, what I am i missing?
Posted

1 solution

The date() function returns a date format as string not a date, refer http://php.net/manual/en/function.date.php[^]
If your purpose is to insert the current date time that the booking takes place, you can set this as default value for the particular field of the database table, then you do not have to worry about inserting the correct date time anymore. Check this out:http://www.w3schools.com/sql/func_now.asp[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900