1
主要基於ID的記錄複選框,我試圖表現出什麼用戶就列出了信息的更新和
BookID date time confirmed
證實是0或1,0未確認1確認,因爲這是一個表,這需要完成$ _GET我假設或它不會更新正確的。
此刻我有這樣的表格,列出了事情
<?php
while($row = mysqli_fetch_array($result))
{ ?>
<tr>
<td><?php echo $row['BookID']?></td>
<td> <?php echo $row['date']?> </td>
<td> <?php echo $row['time']?> </td>
<td> <input type="checkbox" name="Confirmed" value="1" <?php echo ($row['Confirmed'] == 1) ? 'checked="checked"' : ''; ?>/> </td>
<td><a href="delete.php?BookID=<?php echo $row['BookID']; ?>">Delete</a></td>
<td><a href="update.php?BookID=<?php echo $row['BookID']; ?>">Update</a></td>
</tr>
</table>
update.php包含此
<?php
// Your database info
$db_host = 'localhost';
$db_user = 'root';
$db_pass = '';
$db_name = 'smithrwg_database';
$Confirmed = $_POST['Confirmed'];
if (!isset($_POST['Confirmed']))
{
echo 'No ID was given...';
exit;
}
$con = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($con->connect_error)
{
die('Connect Error (' . $con->connect_errno . ') ' . $con->connect_error);
}
$sql = mysql_query("UPDATE tbl_booking SET Confirmed = '$Confirmed' WHERE BookID = ?");
//$sql = "UPDATE tbl_booking SET Confirmed='$Confirmed' WHERE BookID == ?";
if (!$result = $con->prepare($sql))
{
die('Query failed: (' . $con->errno . ') ' . $con->error);
}
if (!$result->bind_param('i', $_GET['BookID']))
{
die('Binding parameters failed: (' . $result->errno . ') ' . $result->error);
}
if (!$result->execute())
{
die('Execute failed: (' . $result->errno . ') ' . $result->error);
}
if ($result->affected_rows > 0)
{
echo "The ID was updated with success.";
}
else
{
echo "Couldn't update the ID.";
}
$result->close();
$con->close();
與我的主要重點是在$ SQL,因爲它不是實際得到來自get函數的id。
該複選框正在從數據庫中獲取值以查看它是否應該已經被檢查或者沒有,我希望能夠再次單擊它並「未確認」或確認它是否沒有勾號。
爲什麼$ _POST ['確認']而不是$ _GET ['確認']? – MIIB
改爲$ _GET它並沒有真正做任何事情。也改變了'Update'到'Update' – user3381055
這條線呢?如果(!isset($ _ POST ['Confirmed'])) – MIIB