php 在线问卷调查程序
<html> <head> <title>问卷调查</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <style type="text/css"> <!-- body { background-color: #330104; text-align: center; background-image: url(images/bg.jpg); background-repeat: repeat-x; color: #fee0a8; margin: 0px; padding: 0px; } * { margin: 0px; padding: 0px; } #poll { width: 650px; margin-left: 100px; } #poll h1 { font-size: 12px; font-weight: normal; padding-top: 30px; line-height: 22px; height: 22px; } table.pollt { line-height: 24px; height: 24px; margin-top: 22px; } input.inputt { border: 1px solid #FEE0A8; background-color: #FFF9EC; } input.btn { background-image: url(images/btn.gif); display: block; height: 32px; width: 97px; color: #FEE0A8; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; background-color: #240002; } --> </style> <script> <!-- function check() { var flag1=0; var flag2=0; var flag3=0; var flag4=0; var flag5=0; var flag6=0; var radio1=document.getElementsByName("v1"); for(var i=0;i<radio1.length;i++) { if(radio1.item(i).checked==true) { flag1=1; break; } } var radio2=document.getElementsByName("v2"); for(var i=0;i<radio2.length;i++) { if(radio2.item(i).checked==true) { flag2=1; break; } } var radio3=document.getElementsByName("v3"); for(var i=0;i<radio3.length;i++) { if(radio3.item(i).checked==true) { flag3=1; break; } } var radio4=document.getElementsByName("v4"); for(var i=0;i<radio4.length;i++) { if(radio4.item(i).checked==true) { flag4=1; break; } } var radio5=document.getElementsByName("v5"); for(var i=0;i<radio5.length;i++) { if(radio5.item(i).checked==true) { flag5=1; break; } } var radio6=document.getElementsByName("v6"); for(var i=0;i<radio6.length;i++) { if(radio6.item(i).checked==true) { flag6=1; break; } } if(!flag1||!flag2||!flag3||!flag4||!flag5||!flag6){ alert("对不起,请回答完其他的问题?"); return false; } if (add.name.value=="") { alert("请输入用户名!"); add.name.focus(); return false; } if (add.name.value.length<2 || add.name.value.length>14) { alert("姓名应该在2-14个字符之间!"); add.name.focus(); return false; } if (add.tel.value==""){ alert("请输入电话或手机号码!"); add.tel.focus(); return false; } if (add.email.value==""){ alert("请输入电子邮件地址!"); add.email.focus(); return false; } var filter=/^s*([A-Za-z0-9_-]+(.w+)*@(w+.)+w{2,3})s*$/; if (!filter.test(document.add.email.value)) { alert("邮件地址不正确,请重新填写!"); document.add.email.focus(); document.add.email.select(); return (false); } if (add.address.value == ""){ alert("请输入你的联系方式") add.email.focus(); return false; } } //--> </SCRIPT> </head> <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <!-- ImageReady Slices (问卷调查.psd) --> <table id="__01" width="1002" height="1100" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"> <img src="images/index_01.jpg" width="1002" height="57" alt=""></td> </tr> <tr> <td colspan="2"> <img src="images/index_02.jpg" width="1002" height="107" alt=""></td> </tr> <tr> <td height="811" colspan="2" valign="top" background="images/index_03.jpg"> <div id="poll"> <form action="post.php" method="post" name="add" enctype="multipart/form-data" onSubmit="return check();" > <h1>1、泸州老窖特曲有多少年的历史?</h1> <input name="v1" type="radio" value="300年">300年 <input name="v1" type="radio" value="400年">400年 <input name="v1" type="radio" value="1000年">1000年 <h1>2、浓香型白酒又被称为什么香型?</h1> <input name="v2" type="radio" value="酱香型">酱香型 <input name="v2" type="radio" value="奇香型">奇香型 <input name="v2" type="radio" value="泸型">泸型 <h1>3、泸州老窖特曲曾代表中国获得最早什么国际大奖?</h1> <input name="v3" type="radio" value="巴拿马万国博览会金奖">巴拿马万国博览会金奖 <input name="v3" type="radio" value="巴西博览会金奖">巴西博览会金奖 <input name="v3" type="radio" value="巴拿马糖烟酒会金奖">巴拿马糖烟酒会金奖 <h1>4、泸州老窖特曲曾获得什么称号?</h1> <input name="v4" type="radio" value="物质文化遗产">物质文化遗产 <input name="v4" type="radio" value="非物质文化遗产">非物质文化遗产 <h1>5、此次泸州老窖特曲推出的赠品名称为?</h1> <input name="v5" type="radio" value="金奖珍藏">金奖珍藏 <input name="v5" type="radio" value="传世浓香">传世浓香 <input name="v5" type="radio" value="传世珍藏">传世珍藏 <h1>6、在此次泸州老窖特曲促销活动中,您买多少瓶特曲就能获得“传世珍藏”大礼?</h1> <input name="v6" type="radio" value="2瓶">2瓶 <input name="v6" type="radio" value="4瓶">4瓶 <input name="v6" type="radio" value="6瓶">6瓶 <table class="pollt" width="489" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="108">您的姓名</td> <td width="381"><label> <input type="text" class="inputt" name="name" id="name"> </label></td> </tr> <tr> <td>您的电话</td> <td><input type="text" class="inputt" name="tel" id="tel"></td> </tr> <tr> <td>您的E-mail</td> <td><input type="text" class="inputt" name="email" id="email"></td> </tr> <tr> <td>您的联系方式</td> <td><input name="address" type="text" class="inputt" id="address" size="50"></td> </tr> </table> <table border="0" align="center" cellpadding="0" cellspacing="20"> <tr> <td align="center"><input name="" type="submit" class="btn" value="提交"></td> <td align="center"><input name="重置" type="reset" class="btn" value="重新作答"></td> </tr> </table> </form> </div> </td> </tr> <tr> <td> <img src="images/index_04.jpg" width="17" height="125" alt=""></td> <td> <img src="images/index_05.jpg" width="985" height="125" alt=""></td> </tr> </table> <!-- End ImageReady Slices --> </body> </html>
这里是后台和数据库代码:
CREATE TABLE IF NOT EXISTS `su_mon_vote` ( `id` int(11) NOT NULL auto_increment, `v1` varchar(100) default NULL, `v2` varchar(200) NOT NULL, `v3` varchar(200) NOT NULL, `v4` varchar(200) NOT NULL, `v5` varchar(200) NOT NULL, `v6` varchar(200) NOT NULL, `name` varchar(50) NOT NULL, `tel` varchar(50) NOT NULL, `email` varchar(50) NOT NULL, `address` varchar(200) NOT NULL, `vip` varchar(20) NOT NULL, `vdate` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=gb2312 AUTO_INCREMENT=6 ;上面的结构是随便写的没注意数据库其它方面报.好下面我们来看看php程序是怎么判断调查的吧. if(empty($_COOKIE["cook"])){ mysql_connect('localhost','root','mailangel') or die('database server no exists!'); mysql_select_db('vot') or die('database error!'); mysql_query("SET NAMES 'gbk'");//set document charset encode $name =get_value("name",'post'); $tel =get_value("tel",'post'); $email =get_value("email",'post'); $add =get_value("address",'post'); $vip =get_real_ip(); $date =date("Y-m-d h:i:s"); $value =$_SERVER['HTTP_HOST']; $array =array(); for($i=1;$i<=6;$i++){ $v ='v'.$i; $v =get_value("$v",'post'); $array[$i-1]=$v; if(empty($v)){ alert('对不起,你还有选项未选!',''); } } if( strlen($name)>100 || strlen($name)<3 ) { alert('用户名长度3-20',''); }elseif( strlen($tel)>15 || strlen($tel)<7){ alert('请输入正确的电话号码!',''); }elseif( strlen($email)>50 || strlen($email)<10 ) { alert('对不起,你的邮箱地址不正确!',''); }elseif( strlen($add)>100 || strlen($add)<10 ){ alert('地址长度10-100字符!',''); } $sql ="Insert into su_mon_vote(v1,v2,v3,v4,v5,v6,name,email,address,vip,vdate,tel) value( "; $sql =$sql."'".$array[0]."','".$array[1]."','".$array[2]."','".$array[3]."','".$array[4]."','".$array[5]."','$name',"; $sql =$sql."'$email','$add','$vip','$date','$tel')"; //mysql_query($sql) or die($sql.mysql_error()); if( mysql_query($sql)){ setcookie("cook", $value, time()+7200, "/"); alert('答题成功,谢谢你的参与!','index.html'); }else{ alert('系统忙...请稍后再试',''); } }else{ print "答题失败,一人只能参加一次答题!,<a href=# onclick="history.back();">点击返回</a>"; } function get_value($para,$para2){//获取参数的值 if( 'post'==$para2 ){ return addslashes(isset($_POST[$para])?$_POST[$para]:''); }else{ return addslashes(isset($_GET[$para])?$_GET[$para]:''); } } function alert($str,$para){//提示设置函数, if( ''== $para){ exit("<script>alert('$str');history.back();</script>"); }else{ exit("<script>alert('$str');location='$para';</script>"); } } function get_real_ip(){ $ip=false; if(!empty($_SERVER["HTTP_CLIENT_IP"])){ $ip = $_SERVER["HTTP_CLIENT_IP"]; } if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']); if ($ip) { array_unshift($ips, $ip); $ip = FALSE; } for ($i = 0; $i < count($ips); $i++) { if (!eregi ("^(10|172.16|192.168).", $ips[$i])) { $ip = $ips[$i]; break; } } } return ($ip ? $ip : $_SERVER['REMOTE_ADDR']); } ?>