📄 vote.php
字号:
<?php
// 包含数据库连接文件和头文件
require ('dbconnect.php');
include('head.php');
// 获得参数,得到投票主题id
$id=$_GET[id];
?>
<script language="javascript">
function checkvote()
{
if (form1.email.value=="")
{
// 如果没有输入email,则显示警告信息
alert("请输入email!");
form1.email.focus();
return false;
}
// 检查email格式是否正确
else if (form1.email.value.charAt(0)=="." ||
form1.email.value.charAt(0)=="@"||
form1.email.value.indexOf('@', 0) == -1 ||
form1.email.value.indexOf('.', 0) == -1 ||
form1.email.value.lastIndexOf("@")==form1.email.value.length-1 ||
form1.email.value.lastIndexOf(".")==form1.email.value.length-1)
{
alert("Email的格式不正确!");
form1.email.select();
return false;
}
else{
return true;
}
}
</script>
<html>
<body>
<form name="form1" method="post" action="add_vote.php?id=<? echo $id;?>" onsubmit="return checkvote()">
<table width="70%" border="1" cellspacing="1" cellpadding="3" align="center">
<tr>
<th colspan="2">欢迎投票</th>
</tr>
<?
// 构造读取数据的sql语句
$titlesql="select * from title where id='$id'";
$titleresult=mysql_query($titlesql,$conn);
$title=mysql_fetch_array($titleresult);
echo "<tr>";
echo "<td width='45%'>$title[title]";
if ($title[types]==1){
echo "<br>(单选)</td>";
}
else{
echo "<br>(多选)</td>";
}
// 从vote表中取出投票选项
$votesql="select * from vote where titleid='$id'";
$voteresult=mysql_query($votesql,$conn);
// 显示投票选项
echo "<td><table>";
echo "<input type='hidden' name='types' value='$title[types]'>";
while($info=mysql_fetch_array($voteresult)){
echo "<tr><td width='55%'>";
// 单选
if ($title[types]==1){
echo "<input type='radio' name='select' value=$info[id]>";
echo "$info[info]</td</tr>";
}
// 多选
else{
echo "<input type='checkbox' name='select[]' value=$info[id]>";
echo "$info[info]</td</tr>";
}
}
echo "</table></td>";
echo "</tr>";
?>
<tr>
<td >
请输入您的Email:
</td>
<td>
<input type="text" name="email" size="50" maxlength="200">
</td>
</tr>
<tr>
<td align=right >
<input type="submit" name="Submit" value="提交">
</td>
<td>
<input type="reset" name="Submit2" value="重置">
</td>
</tr>
</table>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -