我正在嘗試使用之前添加的php將某些值更新到數據庫。我嘗試添加的其中一個數據是日期值。雖然第一次添加該值時,所有內容都會正確添加。當我嘗試更新日期值時,數據更改爲0000-00-00始終。所以我有以下問題:更新到null的日期
1)我犯的錯誤是什麼,日期未正確更新?
2)如何將日期的格式更改爲DD/MM/YYYY?
這是更新的代碼(我知道我的風險SQL注入,但是這不是我在這個時候關注):
<?php
//DISPLAY A LIST OF ALL Files
$sql = "select * from news";
$result = mysqli_query($mydb, $sql) or die(mysqli_error($mydb));
if(mysqli_num_rows($result)>0){
?>
<table class="table table-striped" >
<thead>
<td><b>NewsID</b></td>
<td><b>Headline</b></td>
<td><b>Story</b></td>
<td><b>Date</b></td>
<td><b>Actions</b></td>
</thead>
<tbody>
<?php while($rows=mysqli_fetch_array($result)){
$NewsID = $rows['NewsID'];
$Headline = $rows['Headline'];
$Story = $rows['Story'];
$Date= $rows['Date'];
?>
<tr>
<form method="post" id="action" action="<?php $_SERVER['PHP_SELF']?>">
<?php //if update button was pressed change all plain text to textfields to enable inline editing
if (isset($_POST['preUpdate']) && $_POST['NewsID']==$NewsID) { ?>
<td><?php echo $NewsID ?></td>
<td><input type="text" name="Headline" value="<?php echo $Headline?>"></td>
<td><input type="text"name="Story" value="<?php echo $Story?>"></td>
<td><input type="date" name="Date" value="<?php echo $Date?>"></td>
<td><input type="submit" name="update" value="Save"/></td>
<?php }
else { //These file will be displayed in plain text ?>
<td><?php echo $NewsID; ?> </a></td>
<td><?php echo $Headline; ?></td>
<td><?php echo $Story; ?></td>
<td><?php echo $Date; ?></td>
<td><input type="submit" name="preUpdate" value="Update"/>
<input type="submit" name="delete" value="delete"/></td>
<?php } // end of if update button was pressed ?>
<input type="hidden" name="NewsID" value="<?php echo $NewsID?>">
</form>
</tr>
<?php } //end of while loop that displays courses ?>
</tbody>
</table>
<?php }
你是什麼日期列的類型? – Akshay
請發佈更新表格並設置日期的代碼。我所看到的只是一個「選擇」而沒有「插入」或「更新」。 –
人們可能會認爲在更新單詞的12次出現中,有1次會顯示 – Drew