2013-08-03 36 views
0

我使用PHP/MySQL創建事件系統,我使用PHP將日期拼湊在一起形成一個字符串。我希望我的日期格式爲dd-mm-yy。我使用下面的代碼:PHP undefined offset

$title = $_POST['title']; 
     $title = htmlspecialchars($title); 
     $type = $_POST['evtype']; 
     $type = htmlspecialchars($type); 
     $evdesc = $_POST['evdesc']; 
     $evdesc = htmlspecialchars($evdesc); 
     $startdate = (isset($_POST['startdate'])) ? $_POST['startdate'] : '' ; 
     $starttime = $_POST['starttime']; 
     $starttime = htmlspecialchars($starttime); 
     $enddate = (isset($_POST['enddate'])) ? $_POST['enddate'] : '' ; 
     $endtime = $_POST['endtime']; 
     $endtime = htmlspecialchars($endtime); 
     $location = $_POST['location']; 
     $location = htmlspecialchars($location); 
// assemble dates and times 
list($startday, $startmonth, $startyear) = array_pad(explode('-', $startdate, 2), 2, null); 
$evstart = '' . $startyear . '-' . $startmonth . '-' . $startday . ' ' . $starttime . ''; 

list($endday, $endmonth, $endyear) = array_pad(explode('-', $enddate, 2), 2, null); // explode("-", $enddate); 
$evend = '' . $endyear . '-' . $endmonth . '-' . $endday . ' ' . $endtime . ''; 
     // end assemble 

然而,這個代碼不爆炸的數據,唯一的事情,帖子到數據庫後上「 - (一次在這裏)」

錯誤分別是:

注意:未定義抵消:2 calendar.php上線42

注意:未定義抵消:2 calendar.php在線45

+0

你已經告訴你所訪問未定義的陣列,在線路42偏移和45何不你只是看看這些線路上有什麼,並嘗試調試它? – MightyPork

+0

@MightyPork 42和45是兩個list()函數 – James

回答

1

您使用

array_pad(/* something*/, 2, null) 

並期望在數組中獲得三個項目。

list($startday, $startmonth, $startyear) = ... 

我想如果你改變這個23,它會工作得很好。

(對於這個問題,您應該explode()limit = 3,不2,太)

array_pad() reference