2012-05-24 30 views
1

我有具有以下表的HTML文件上:致命錯誤:調用一個成員函數格式()非對象

<form action="wedding-ajax-support.php" method="get" id="wedding-table"> 
<table border="0"; align="center"> 
    <tr> 
    <th scope="col">Key</th> 
    <th scope="col">Value</th> 
    </tr> 
    <tr> 
    <td><label for="date">Select the date on which your party will take place (mm/dd/yyyy): </label></td> 

    <td> 
     <input name="date" type="text" class="larger" id="date" size="12" /> 
    </td> 
    </tr> 
    <tr> 
    <td><label for="catering">Type the catering grade you would like (from 1 to 5) : </label></td> 
    <td><input name="catering" type="text" class="larger" id="catering" size="5" /></td> 
    </tr> 
    <tr> 
    <td><label for="size">Type the number of people you are expecting to attend: </label></td> 
    <td><input name="size" type="text" class="larger" id="size" size="5" /></td> 
    </tr> 
    <tr> 
    <td>Find me available venues, based on my preferences: </td> 
    <td><input type="submit" name="submit" id="submit" value="GO!" class="larger" /></td> 
    </tr> 
</table> 

One of those inputs is the date. That's the only thing I'm concerned about for now, to keep things simple.

On another file, wedding-ajax-support.php (on which I organize all of my php code) I have this amongst other code:

$date = DateTime::createFromFormat('m/d/Y', $_GET['date']); 

$日期= $日期 - >格式( 'YM-d'); //更改日期的格式,如用戶輸入的日期,數據庫中的日期格式不同。

And then a simple echo $date; just to test it.

然後,回到我的主文件,我把

<script type="text/javascript"> 

$( 「#婚禮表」)負載( 「婚禮Ajax的support.php」)。

在改變後的格式的日期來替換該表中,通過jQuery使用AJAX。

因此,當我加載我的網頁時,應該顯示一條消息 「致命錯誤:調用/ disks/diskh/zco/cotm2中的非對象的成員函數格式()第23行的/public_html/wedding/wedding-ajax-support.php調用堆棧:0.0002 333936 1. {main}()/disks/diskh/zco/cotm2/public_html/wedding/wedding-ajax-support.php:0「 。

Any ideas/suggestions would be appreciated, thanks in advance!

+0

不要使用日期其文本字段的問題,使用日曆(腳本),然後你可以suer的格式。 – 2012-05-24 04:08:58

回答

0

「GET」變量是由Web服務器在URL中作爲查詢參數傳遞時爲PHP設置的。在你的情況下,你正在加載頁面爲"wedding-ajax-support.php",這意味着_GET變量實際上是空的。

0

錯誤告訴你的

$date = DateTime::createFromFormat('m/d/Y', $_GET['date']); 

結果不是DateTime實例,但最有可能的false因爲the php doc for DateTime提到,false會,如果它不能創建基於給定參數的情況下返回。

因此,與

$date = $date->format('Y-m-d'); 

您要調用的方法format()false,這是沒有對象。

你應該知道爲什麼createFromFormat失敗。這可能是$_GET['date']處於無法解析的格式,或者它只是空的。試試var_dump($_GET)找出答案。

至於對方的回答中指出,$_GET變量附加到URL,因此對於$_GET['date']要設置的URL看起來應該像wedding-ajax-support.php?date=xyz例如。

不幸的是,我沒有得到你試圖做的JavaScript來幫助你進一步。

編輯:哇這個帖子很舊。之前沒有看到它,對不起。

相關問題