我从数据库传递日期并设置dateforService的值,然后我将URL值发送到另一个php文件以更新数据库。但每当我尝试保存在db中时,它都保存为0000-00-00。
以下是以下代码:
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 :(得分:0)
替换
dateforService = $dateforService
带
dateforService = '$dateforService'
以防万一
替换
jobrequestnumber ='$jobrequestnumber' // remove { & }. You are not using an array here. And add quotes around it