我想創建一個刪除選項或按鈕,用戶可以輸入id並刪除他們的約會,但目前如果他們輸入任何id它會刪除它,我想限制用戶,使他們只能刪除他們的約會而不是其他用戶約會。任何幫助都會很棒。這裏是我目前有:使用pdo登錄用戶詳細信息刪除行php
<?php foreach($rows as $row): ?>
<tr>
<td><?php echo htmlentities($row['id'], ENT_QUOTES, 'UTF-8'); ?></td>
<td><?php echo htmlentities($row['date'], ENT_QUOTES, 'UTF-8');
?></td>
<td><?php echo htmlentities($row['month'], ENT_QUOTES, 'UTF-8');
?></td>
<td><?php echo htmlentities($row['hour'], ENT_QUOTES, 'UTF-8');
?></td>
<td><?php echo htmlentities($row['minute'], ENT_QUOTES, 'UTF-8');
?></td>
<td><?php echo htmlentities($row['illness'], ENT_QUOTES, 'UTF-8');
?></td>
<td><a href="delete_memberapp.php?id=<?php echo $row['id']; ?>">
delete </a></td>
</tr>
<?php endforeach; ?>
</table><br />
這裏是形式
<form action="delete.php" method="post">
Enter Booking reference to delete appointment : <input type="text"
name="id" required><br><br>
<input type="submit" name="delete" value="Delete appointment">
</form>
這裏是刪除文件:
if(isset($_POST['delete']))
{
try {
$pdoConnect = new PDO("mysql:host=localhost;dbname=doctor","root","");
} catch (PDOException $exc) {
echo $exc->getMessage();
exit();
}
$id = $_POST['id'];
$pdoQuery = "DELETE FROM `booking` WHERE `id` = :id";
$pdoResult = $pdoConnect->prepare($pdoQuery);
$pdoExec = $pdoResult->execute(array(":id"=>$id));
if($pdoExec)
{
echo 'Data Deleted';
}else
{
echo 'ERROR Data Not Deleted';
}
}
表結構:
--
-- Table structure for table `booking`
--
CREATE TABLE IF NOT EXISTS `booking` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(10) NOT NULL,
`phone` varchar(10) NOT NULL,
`date` varchar(4) NOT NULL,
`month` varchar(10) NOT NULL,
`hour` varchar(5) NOT NULL,
`minute` varchar(5) NOT NULL,
`illness` varchar(10) NOT NULL,
`call_patient` varchar(3) NOT NULL,
`username` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=80 ;
這不起作用 – asaf
@asaf你能提取會話用戶ID嗎?那個var的名字是什麼?你有沒有在你的預訂表中的用戶名列? – Standej
這是我的顯示屏查詢,顯示在用戶登錄的appointmens: $查詢= 「 選擇 \t ID, 日期, 月, 小時, 分鐘, 疾病 從預訂其中username =「」。 $ _SESSION ['user'] ['username']。「' 」; – asaf