[英]Move image from one table to another using button
我正在創建一個按鈕,允許管理員驗證來自用戶的圖像:
當我點擊接受或拒絕時,我不知道如何獲取圖像 ID。
這是我的代碼:
<?php
while($row = mysqli_fetch_array($result)) {
echo "<div class='grid-item'><img src='unimages/{$row['un_image']}'
onclick=onClick(this) style='width:98%' class='verifyimage' />
<form method='post' action='adminverify.php'>
<input class='button1' type='submit' name='accept' value='✓'>
<input class='button2' type='submit' name='reject' value='✘'>
</form>
</div>
";
}
mysqli_close($db);
?>
</div>
如果管理員接受,則圖像應從 table2 移動到 table1。
我知道使用INSERT INTO
和DELETE
會起作用,但是如何獲取我的圖片的 ID。
表格1:
表 2:
嗯,您可以使用 GET 方法來簡化腳本:
while($row = mysqli_fetch_array($result)) {
echo "
<a href='?&action=accept&id={$row['un_id']}'>Accept</a>
<a href='?&action=reject&id={$row['un_id']}'>Reject</a>
";
}
你像這樣使用它:
if(isset($_GET['action']) && isset($_GET['id'])) {
$image_id = $_GET['id']
// Then check if you must accept or reject with $_GET['action'] value
}
我將添加一個將與表單一起發送的隱藏輸入:
echo "<div .....
<form....>
<input type='hidden' name='imageId' value='{$row['un_id']}'>
....
</form></div>";
然后,您將在接收的 php 腳本中將其作為
$image_id = $_POST['imageId'];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.