In this section we introduce the administrator to modify voting items and delete voting items.
Query the database through the SQL statement SELECT and loop out all voting items
<?php $SQL="SELECT * FROM vote order by count desc"; $rs=mysqli_query($link,$sql); while($rows=mysqli_fetch_assoc($rs)) { ?> <tr> <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="itm" value="<?php echo $rows["id"]?>" /><?php echo $rows["id"]?></td> <td align="center" bgcolor="#FFFFFF"><?php echo $rows["item"]?></td> <td align="center" bgcolor="#FFFFFF"><?php echo $rows["count"]?></td> <td align="center" bgcolor="#FFFFFF"><input type="button" value="修改" onclick="location.href='?type=modify&id=<?php echo $rows["id"]?>'" /></td> <td align="center" bgcolor="#FFFFFF"><input type="button" value="删除" onclick="location.href='?type=del&id=<?php echo $rows["id"]?>'" /></td> </tr> <?php } ?>
Use <input type="checkbox"/> to select the required The one that was modified and deleted.
<input type="checkbox" name="itm" value="<?php echo $rows["id"]?>" />
The modification and deletion here are given to the id, and the current content is modified through the obtained id, and the data in the database is modified.
<?php $type = isset($_GET["type"])?$_GET["type"]:""; if($type =="modify"){ $id=$_GET["id"]; $item=$_POST["itm"]; $count=$_POST["count"]; $SQL="UPDATE vote SET item='$item',count=$count WHERE id=$id"; mysqli_query($link,$sql); echo "<script language=javascript>alert('修改成功!');window.location='admin.php'</script>"; } ?>
Delete the current project and delete the data in the database by obtaining the id value.
<?php $type = isset($_GET["type"])?$_GET["type"]:""; if($type =="del"){ $id=$_GET["id"]; $SQL="DELECT FROM vote WHERE id in ($id)"; mysqli_query($link,$sql); echo "<script language=javascript>alert('删除成功!');window.location='admin.php'</script>"; } ?>