我試圖生成引腳和序列號存儲在數據庫中並顯示基於需求。例如,如果有人需要1或2引腳和序列號,在顯示這些引腳和序列號後,我想更新它們的值,以使其不能再次生成。我無法更新值。從數據庫更新數據從數據庫獲取數據
<?php
if (isset($_POST['card']) && isset($_POST['cn'])) {
$card = $_POST['card'];
$no_of_pin = $_POST['cn'];
if (!empty($card) && !empty($cn)){
$query =mysql_query("SELECT id, pin, sn FROM pin_test WHERE value = '0' LIMIT $no_of_pin");
while($row = mysql_fetch_assoc($query))
echo 'PIN: ' .$row['pin']. ' SN:'. $row['sn']. ' id:'. $row['id'].'<br>';
$pin = $row['pin'];
$sn = $row['sn'];
$id = $row['id'];
$query2 = "UPDATE pin_test SET value = '1' WHERE id = $id";
if(mysql_query($query2)){
echo 'Successful';
}else{
echo 'Unsuccessful';
}
}else{
echo 'All fields are required.';
}
}
?>
請正確地格式化代碼下一次。你不能指望我們這樣做。 – Tunaki