I have a form with a few fields, mostly text, but also have a Date and a Time field. Im not quiet sure on how to save these to the database table tho. In PHPMyAdmin, I have set the "eventdate" field to DATE type, and "time" field to "TIME" type.
In my JS file, i have:
// When "Save Event" is clicked
form.submit({point: point}, function (event) {
// Stops page from refreshing
event.preventDefault();
// Form validation
if( !$("input[name=name]", this).val() ) {
alert('You forgot to enter a name!');
return false;
}
if( !$("textarea[name=description]", this).val() ) {
alert('You forgot to enter a description!');
return false;
}
// Send elements to 'data' object.
var data = {
name: $("input[name=name]", this).val(),
description: $("textarea[name=description]", this).val(),
category: $("select[name=type]",this).val(),
eventdate: $("input[name=date]", this).val(),
time: $("input[name=time]", this).val(),
lat: event.data.point.overlay.getPosition().lat(),
lon: event.data.point.overlay.getPosition().lng()
};
trace(data)
// Sends data to PHP script to database
$.post("add_event_data.php", data, tidy_maps.saveStopResponse, "json");
And the corresponding PHP is:
// Insert into DB table "Events"
$statement->prepare("INSERT INTO events (lat, lon, name, description, category, eventdate, time) VALUES (?, ?, ?, ?, ?, ?, ?)");
// Add values from the url and add to DB
$statement->bind_param("ddsssss", $_POST['lat'], $_POST['lon'], $_POST['name'], $_POST['description'], $_POST['category'], $_POST['eventdate'], $_POST['time']);
$status = $statement->execute();
Its clearly not sending the data to the DB and it must be due to Date and Time, because it was working with another DB Table before i added these in.