<!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> <a href="createvote.html">添加投票(管理员部分)</a><br /> <a href="delvote.php">删除投票(管理员部分)</a><br /> <a href="voteindex.php">投票(普通用户部分)</a> </body> </html>
<!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>
<button onclick="createbtn()">增加选项</button> <button onclick="delbtn()">删除选项</button>
<!--onsubmit属性是为了下面脚本能够顺利弹出确认框,用户确认之后才提交这个表单-->
<form action="createvote.php" method="post" onsubmit="return check()">
<!--这里定义div的id是为了下面的javascript的操作,而且div不像p那样会参加很大的行距-->
<div id="createform">
<div>
投票主题:<input type="text" name="title" style = "width:70%"/>
</div>
<div>
投票描述:<input type="text" name="text" style = "width:70%"/>
</div>
<div>
选项1:<input type="text" name="opt1" style = "width:70%"/>
</div>
<div>
选项2:<input type="text" name="opt2" style = "width:70%"/>
</div>
</div>
<!--这里是用来记录有多少个选项的-->
<input type="hidden" id="nodetotal" name="nodetotal" />
<input type="submit" value="提交" />
</form>
<a href="index.html">返回</a>
</body>
</html>
<script>
//脚本部分,是现实的关键
//开始先记录当前的选项数是2,并存入hidden域,到时候随表单一起提交
var nodenum=2;
document.getElementById("nodetotal").value=nodenum;
//下面是“增加选项”“删除选项”的按钮操作
function createbtn(){
//如果选项少于10个才操作
if(nodenum<10){
nodenum++;
var node=document.createElement("div");
//操作节点如果涉及html文本,写成单引号就不用写\"这么难看的双引号的转义字符
node.innerHTML="选项"+nodenum+":<input type='text' name='opt"+nodenum+"' style='width:70%' />";
document.getElementById("createform").appendChild(node);
//记得增加完每个节点,要更新以下hidden域里面的节点数哦!
document.getElementById("nodetotal").value=nodenum;
}
else{
alert("最多10个选项");
}
}
//逻辑跟上面一样
function delbtn(){
if(nodenum>2){
nodenum--;
d=document.getElementById("createform");
d.removeChild(d.lastChild);
document.getElementById("nodetotal").value=nodenum;
}
else{
alert("至少2个选项");
}
}
//表单确认框的脚本,表单onsubmit为true才能够提交嘛,confirm点确定则返回true反之为false
function check(){
return confirm("确定提交?");
}
</script>
<!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
//首先取出刚才要添加投票的title与text,隐藏域中的选项数
$ptitle=$_REQUEST["title"];
$ptext=$_REQUEST["text"];
$nodetotal=$_REQUEST["nodetotal"];
$con=mysql_connect("localhost","root","root");
//连接数据库
if(!$con){
die("连接失败!");
}
mysql_select_db("test",$con);
mysql_query("set names utf8");
//把title与text插入到voteparent表,设定删除位是0之后,系统会自动生成id
mysql_query("insert into voteparent(title,text,isdel) values ('".$ptitle."','".$ptext."',0);");
//再通过title找到刚才系统生成的id
$pid;
$result=mysql_query("select id as pid from voteparent where title='".$ptitle."';");
while($row=mysql_fetch_array($result)){
$pid=$row["pid"];
}
//建立一个php数组,里面存放每一个子选项
$optarr=array();
//选项的多少决定了我们的循环次数
for($i=1;$i<$nodetotal+1;$i++){
$optarr[$i]=$_REQUEST["opt${i}"];
mysql_query("insert into votechildren(text,count,parentid) values ('".$optarr[$i]."',0,'".$pid."');");
};
mysql_close($con);
?>
</body>
</html>
<script>
alert("添加成功");
window.location.href="index.html";
</script>
<!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 style='margin-right:10px;float:left'>投票${i}:<a href='vote.php?id=${row["id"]}'>${row["title"]}</a></div><div style='float:left'><button id='${row["id"]}' onclick='deljs(this.id)'>删除</button></div><div style='clear:both'></div>";
$i++;
}
mysql_close($con);
?>
<p>
<a href="index.html">返回</a>
</p>
</body>
</html>
<script>
function deljs(id){
if(confirm("确认删除?")){
window.location.href="delvotehandle.php?id="+id;
}
}
<!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 id=".$pid.";");
mysql_close($con);
?>
</body>
</html>
<script>
alert("删除成功");
window.location.href="index.html";
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有