我需要將簽出用戶點擊按鈕之後插入一個時間戳到表遊客柱而出。將簽出按鈕已刪除表中的行liveroster
但在與時間戳列了它沒有更新表遊客行。插入MySQL數據到exsisting行
mysql_query("UPDATE visitors SET out=test WHERE ID=" . $ID);
<?php
/*
Connection Stuff
*/
if (isset($_POST['ID'])) {
$ID = $_POST['ID'];
if (isset($_POST['delete_id'])) {
mysql_query("UPDATE visitors SET out=test WHERE ID=" . $ID);
mysql_query("DELETE FROM liveroster WHERE ID = " . $ID);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
#delete-post {
width: 100%;
margin: auto;
background-color: #999;
}
</style>
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
</head>
<body>
<div>
<table border cellpadding="3">
<tr>
<td></td>
<td><strong>Time</strong></td>
<td><strong>Name</strong></td>
<td><strong>Teacher</strong></td>
<td><strong>Reason</strong></td>
</tr>
<?php
$data = mysql_query("SELECT * FROM liveroster") or die(mysql_error());
while($info = mysql_fetch_array($data)){ ?>
<tr>
<th>
<form method="post" action="">
<input type="hidden" name="ID" value="<?php echo $info['ID']; ?>" />
<input type="submit" name="delete_id" value="Sign-Out" />
</form>
</th>
<td>
<?php echo $info['timestamp']; ?>
</td>
<td>
<?php echo $info['name']; ?>
</td>
<td>
<?php echo $info['teacher']; ?>
</td>
<td>
<?php echo $info['reason']; ?>
</td>
</tr>
<?php } ?>
</table>
</div>
</body>
</html>
兩件事情。 1不要使用** mysql _ ***,因爲它被棄用並且不安全。 2參數化你的查詢,不要只是彈出一個這樣的ID。你可能容易受到sql注入攻擊 –
你想把什麼值放入'out'列?如果你希望它是字符串''test''將你的查詢改爲這個'mysql_query('UPDATE visitor SET ='test'WHERE ID =「。$ ID);' – gellu
@JohnRuddell同意,MYSQLi或PDO是更適合的替代品。 –