我從數據庫傳入日期並設置dateforService的值,然後將URL值發送到另一個php文件以更新數據庫。但每次我嘗試保存在數據庫中,它都保存爲0000-00-00。遇到的格式不正確的數值php
這裏是下面的代碼:
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}";
我很感謝你的建議,非常感謝。
輸入驗證它們傳遞到您的查詢之前!目前它對SQL注入攻擊廣泛開放。什麼給你'var_dump($ dateForService);'? – hek2mgl
dateforService = $ dateforService應該是'dateforService ='$ dateforService'需要圍繞它的「'」 – We0