2013-05-31 63 views
0

我從數據庫傳入日期並設置dateforService的值,然後將URL值發送到另一個php文件以更新數據庫。但每次我嘗試保存在數據庫中,它都保存爲0000-00-00。遇到的格式不正確的數值ph​​p

這裏是下面的代碼:

echo "<td><input type= 'text' name = 'jobrequestnumber' value =".$row['jobrequestnumber']."></td>" ; // results in the same jobrequestnumbers 
echo "<td><input type= 'text' name = 'requestingcompany' value =".$row['requestingcompany']."></td>" ;//this too 
echo "<td><input type= 'date' name = 'dateforService' value =".$row['dateforService']."></td>" ;// this one also 
echo "<td><a href=\"update_request.php?jobrequestnumber={$row['jobrequestnumber']}&requestingcompany={$row['requestingcompany']}&dateforService={$row['dateforService']}\">Update</a></td>"; 

所以,我想下面的更新代碼前右呼應值: 然後出來與正確的日期格式。

if (empty($errors)){ 
$jobrequestnumber = $_GET['jobrequestnumber']; 
$requestingcompany = $_GET['requestingcompany']; 
$dateforService = date("Y-m-d", strtotime($_GET['dateforService'])); 
    $query = "UPDATE jobrequest SET 
         requestingcompany = '{$requestingcompany}', 
         dateforService = $dateforService 
        WHERE jobrequestnumber ={$jobrequestnumber}"; 

我很感謝你的建議,非常感謝。

+0

輸入驗證它們傳遞到您的查詢之前!目前它對SQL注入攻擊廣泛開放。什麼給你'var_dump($ dateForService);'? – hek2mgl

+0

dateforService = $ dateforService應該是'dateforService ='$ dateforService'需要圍繞它的「'」 – We0

回答

0

更換

dateforService = $dateforService 

dateforService = '$dateforService' 

以防萬一

從GET更換

jobrequestnumber ='$jobrequestnumber' // remove { & }. You are not using an array here. And add quotes around it 
+2

您知道單引號表示* literal *值嗎? – Kermit

+0

Yes ofcourse @FreshPrinceOfSO,但整個語句放在雙引號內(「)正確? – Bere

+0

我的錯誤,你是對的,但是在這種情況下,OP需要使用預準備語句 – Kermit

相關問題