eRott Posted May 24, 2009 Share Posted May 24, 2009 Hey, I am having a bit of troubles with this function: function event_add($date, $event_date, $time_start_hh, $time_start_mm, $time_end_hh, $time_end_mm, $event_type, $event_more) { // $date is a date in the format of "dd-mm-yyyy" $timestamp_date = explode('-', $date); // [0] => day [1] => month [2] => year $timestamp_start = mktime($time_start_hh, $time_start_mm, 0, $timestamp_date[1], $timestamp_date[0], $timestamp_date[3]); // mktime(hour, minute, second, month, day, year) $timestamp_end = mktime($time_end_hh, $time_end_mm, 0, $timestamp_date[1], $timestamp_date[0], $timestamp_date[3]); // mktime(hour, minute, second, month, day, year) $query = "INSERT INTO events (date, event_date, start, end, time_start_hh, time_start_mm, time_end_hh, time_end_mm, type, more)"; $query .= "VALUES ('$date', '$event_date', '$timestamp_start', '$timestamp_end', "; $query .= "'$time_start_hh', '$time_start_mm', '$time_end_hh', '$time_end_mm', '$event_type', '$event_more')"; mysql_query($query) or die (mysql_error()); } For some reason, the timestamp isn't being written to the database in the appropriate fields, "start" and "end" while everything else is. I have already checked to ensure neither are reserved MySQL words. I believe it has something to do with my use of the array: $timestamp_date. $date = time(); event_add($date, $_POST['event_date'], $_POST['time_start_hh'], $_POST['time_start_mm'], $_POST['time_end_hh'], $_POST['time_end_mm'], $_POST['event_type'], $_POST['event_more']); Any ideas? Link to comment https://forums.phpfreaks.com/topic/159430-solved-function-troubles/ Share on other sites More sharing options...
hitman6003 Posted May 24, 2009 Share Posted May 24, 2009 time returns the unix timestamp, which is an integer. I think you want to pass something like this... date = date("d-m-Y", time()); Link to comment https://forums.phpfreaks.com/topic/159430-solved-function-troubles/#findComment-841005 Share on other sites More sharing options...
eRott Posted May 24, 2009 Author Share Posted May 24, 2009 Aye. Thanks. I didn't realize I was using the wrong variable. I should have been using $event_date as it is the one which stores the date in the "dd-mm-yyyy" format (which is passed from a form a user fills out). So it should be: // $event_date is a date in the format of "dd-mm-yyyy" $timestamp_date = explode('-', $event_date); // [0] => day [1] => month [2] => year Thanks mate. Take it easy. Link to comment https://forums.phpfreaks.com/topic/159430-solved-function-troubles/#findComment-841007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.