Jump to content

[SOLVED] Function Troubles


eRott

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.