php投票系统之增加与删除投票(管理员篇)(3)

以上,管理员添加投票功能做完,下面是管理员删除投票功能
 4、delvote.php
先把voteparent中所有的删除位不为1的投票查询出来,然后降序排列,因为人们希望先看到最新添加的投票,生成节点的时候设置好每一个投票的删除按钮id,这个id就是在数据库中的voteparent的id,方便后续操作,删除按钮的脚本不用写什么,就是把这个id传到delvotehandle.php,删除处理页中就可以了

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>删除投票</title> </head> <body> <h1>删除投票</h1> <?php $con=mysql_connect("localhost","root","root"); if(!$con){ die("连接失败!"); } mysql_select_db("test",$con); mysql_query("set names utf8"); $result=mysql_query("SELECT * FROM voteparent where isdel=0 order by id desc;"); $i=1; while($row=mysql_fetch_array($result)){ echo "<div>投票${i}:<a href='vote.php?id=${row["id"]}'>${row["title"]}</a></div><div><button>删除</button></div><div></div>"; $i++; } mysql_close($con); ?> <p> <a href="https://www.jb51.net/index.html">返回</a> </p> </body> </html> <script> function deljs(id){ if(confirm("确认删除?")){ window.location.href="delvotehandle.php?id="+id; } }

</script>基本思想就是这样,其中这个页面采用了div布局,而不是table,详情可以参考我之前的《【CSS】关于div的对齐与网页布局》(点击打开链接) 

5、delvotehandle.php
 取到刚才传过来的id,根据这个id把相应的isdel删除位设定为1即可

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>删除投票处理中……</title> </head> <body> <?php $pid=$_REQUEST["id"]; $con=mysql_connect("localhost","root","root"); if(!$con){ die("连接失败!"); } mysql_select_db("test",$con); mysql_query("set names utf8"); mysql_query("update voteparent set isdel=1 where;"); mysql_close($con); ?> </body> </html> <script> alert("删除成功"); window.location.href="https://www.jb51.net/index.html"; </script>

以上就是投票系统管理员部分,增加投票与删除投票的过程,按理说相关的处理页面,还需要进行session的保护,
避免直接输入网址就能够访问,这里没写,可以参考我之前的《php+MySql实现登录系统与输出浏览者信息功能》(点击打开链接

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/d8fe3d594860c1a51cffc3b5bf89aeb6.html