Home php教程 PHP源码 php 在线问卷调查程序一

php 在线问卷调查程序一

Jun 08, 2016 pm 05:30 PM
php Online survey



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>
Copy after login

这里是后台和数据库代码:

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(&#39;localhost&#39;,&#39;root&#39;,&#39;mailangel&#39;) or die(&#39;database server no exists!&#39;);
  mysql_select_db(&#39;vot&#39;) or die(&#39;database error!&#39;); 
  mysql_query("SET NAMES &#39;gbk&#39;");//set document charset encode
  $name =get_value("name",&#39;post&#39;);
  $tel =get_value("tel",&#39;post&#39;);
  $email =get_value("email",&#39;post&#39;);
  $add =get_value("address",&#39;post&#39;);
  $vip =get_real_ip();
  $date =date("Y-m-d h:i:s");
  $value =$_SERVER[&#39;HTTP_HOST&#39;]; 
  
  $array =array();
  for($i=1;$i<=6;$i++){
   $v =&#39;v&#39;.$i;
   $v =get_value("$v",&#39;post&#39;);
   $array[$i-1]=$v;
   if(empty($v)){
    alert(&#39;对不起,你还有选项未选!&#39;,&#39;&#39;);
   }
  } 
  
  if( strlen($name)>100 || strlen($name)<3 ) {
   alert(&#39;用户名长度3-20&#39;,&#39;&#39;);
  }elseif( strlen($tel)>15 || strlen($tel)<7){ 
   alert(&#39;请输入正确的电话号码!&#39;,&#39;&#39;);
  }elseif( strlen($email)>50 || strlen($email)<10 ) {
   alert(&#39;对不起,你的邮箱地址不正确!&#39;,&#39;&#39;);
  }elseif( strlen($add)>100 || strlen($add)<10 ){
   alert(&#39;地址长度10-100字符!&#39;,&#39;&#39;);
  }
  
  $sql ="Insert into su_mon_vote(v1,v2,v3,v4,v5,v6,name,email,address,vip,vdate,tel) value( ";
  $sql =$sql."&#39;".$array[0]."&#39;,&#39;".$array[1]."&#39;,&#39;".$array[2]."&#39;,&#39;".$array[3]."&#39;,&#39;".$array[4]."&#39;,&#39;".$array[5]."&#39;,&#39;$name&#39;,";
  $sql =$sql."&#39;$email&#39;,&#39;$add&#39;,&#39;$vip&#39;,&#39;$date&#39;,&#39;$tel&#39;)";
  //mysql_query($sql) or die($sql.mysql_error());
  if( mysql_query($sql)){
   setcookie("cook", $value, time()+7200, "/");
   alert(&#39;答题成功,谢谢你的参与!&#39;,&#39;index.html&#39;);
   
  }else{
   alert(&#39;系统忙...请稍后再试&#39;,&#39;&#39;);
  }
  
 }else{
   print "答题失败,一人只能参加一次答题!,<a href=# onclick="history.back();">点击返回</a>";
 } 
 
 
 
 function get_value($para,$para2){//获取参数的值
  if( &#39;post&#39;==$para2 ){
   return addslashes(isset($_POST[$para])?$_POST[$para]:&#39;&#39;);
  }else{
   return addslashes(isset($_GET[$para])?$_GET[$para]:&#39;&#39;);
  }
 }
 
 function alert($str,$para){//提示设置函数,
  if( &#39;&#39;== $para){
   exit("<script>alert(&#39;$str&#39;);history.back();</script>");
  }else{
   exit("<script>alert(&#39;$str&#39;);location=&#39;$para&#39;;</script>");
  }
 }
 
  function get_real_ip(){
    $ip=false;
    if(!empty($_SERVER["HTTP_CLIENT_IP"])){
     $ip = $_SERVER["HTTP_CLIENT_IP"];
    }
    if (!empty($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;])) {
     $ips = explode (", ", $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;]);
     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[&#39;REMOTE_ADDR&#39;]);
  }
?>
Copy after login



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

See all articles