PHP的bbs实现之四--创建调查

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:
//createsurvey.sql
CREATE TABLE survey (
  title  varchar(60) NOT NULL,
  totalfield    int(1),
  option1  varchar(60),
  option2  varchar(60),
  option3  varchar(60),
  option4  varchar(60),
  choice1  int(6),
  choice2  int(6),
  choice3  int(6),
  choice4  int(6),
  PRIMARY KEY (title),
  UNIQUE title (title)
);
 
1.survey_admin.php
<?                                                                                            
include "common.inc.php";                                                                     
                                                                                              
if ($Ok)                                                                                      
  {                                                                                           
   if ($choice=="addone")                                                                     
      {                                                                                       
        if ($title=="")                                                                       
          {                                                                                   
             header("Location: login_error.php?error=网上调查的标题为空\n");                  
          }                                                                                   
        if (($option1=="")||($option2==""))                                                   
          {                                                                                   
             header("Location: login_error.php?error=第一、二项不能为空\n");                  
          }                                                                                   
                                                                                              
        $title_check = "select title from survey                                              
          where title = '$title'";                                                            
        $check_result = mysql_query($title_check)                                             
          or die("不能执行网上调查。");                                                       
        $check_num = mysql_num_rows($check_result);                                           
                                                                                              
        $n=2;                                                                                 
        if($option3!="")$n=3;                                                                 
        if($option4!="")$n=4;                                                                 
                                                                                              
        if ($check_num == 0)                                                                  
        {                                                                                     
             $sql = "insert into survey                                                       
                  values('$title','$n', '$option1','$option2',                                
                               '$option3','$option4',1,1,1,1)";                               
                                                                                              
             @mysql_query($sql) or die ("无法添加网上调查");                                  
             header("Location: on_ok.php?log_id=$log_id\n                                     
                               &ok_info=网上调查添加成功");                                   
         }                                                                                    
         else                                                                                 
         {                                                                                    
              header("Location: login_error.php?error=不能重复调查!\n");                     
         }                                                                                    
       }                                                                                      
    else                                                                                      
    if  ($choice == "deleone")                                                                
        {                                                                                     
          $title_check = "select title from survey                                            
              where title = '$title'";                                                        
          $check_result = mysql_query($title_check)                                           
              or die("不能执行网上调查。");                                                   
          $check_num = mysql_num_rows($check_result);                                         
                                                                                              
          if ($check_num == 0)                                                                
            {                                                                                 
              header("Location: login_error.php?                                              
                   error=你选择的网上调查不存在。\n");                                        
             }                                                                                
          else                                                                                
            {                                                                                 
              $title_dele = "delete from survey                                               
                  where title = '$title'";                                                    
              @mysql_query($title_dele) or die ("无法删除网上调查");                          
             header("Location: on_ok.php?log_id=$log_id\n");                                  
             }                                                                                
         }                                                                                    
     }                                                                                        
 include "header.inc.php";                                                                    
?>                                                                                            
                                                                                              
<p align=center>                                                                              
  <font size=5 color=red >                                                                    
      网上调查的管理                                                                          
  </font>                                                                                     
</p>                                                                                          
                                                                                              
<hr color=red>                                                                                
                                                                                              
<BODY>                                                                                        
<FORM METHOD="POST" ACTION="<? echo $PHP_SELF; ?>">                                           
  <TABLE width=80% border=0 align=center bgcolor=yellow>                                      
    <TR  bgcolor=green>                                                                       
      <TD height=20 align=center>                                                             
           <FONT  class=myYellow>                                                             
             添加或者删除一个网上调查!                                                       
          </FONT>                                                                             
      </TD>                                                                                   
    </TR>                                                                                     
    <TR >                                                                                     
      <TD height=50 align=center class=myRed>网上调查的标题:                                 
        <INPUT type=text name=title size=60 maxlength=60>                                     
      </TD>                                                                                   
    </TR>                                                                                     
    <TR >                                                                                     
      <TD height=50 align=center class=myRed>调查的第一项:                                   
        <INPUT type=text name=option1 size=60 maxlength=60>                                   
      </TD>                                                                                   
    </TR>                                                                                     
    <TR >                                                                                     
      <TD height=50 align=center class=myRed>调查的第二项:                                   
        <INPUT type=text name=option2 size=60 maxlength=60>                                   
      </TD>                                                                                   
    </TR>                                                                                     
    <TR >                                                                                     
      <TD height=50 align=center class=myRed>调查的第三项:                                   
        <INPUT type=text name=option3 size=60 maxlength=60>                                   
      </TD>                                                                                   
    </TR>                                                                                     
    <TR >                                                                                     
      <TD height=50 align=center class=myRed>调查的第四项:                                   
        <INPUT type=text name=option4 size=60 maxlength=60>                                   
      </TD>                                                                                   
    </TR>                                                                                     
    <TR>                                                                                      
      <td width="50%" align=center class=myRed>                                               
        <input type="radio" name="choice" value="addone" checked>                             
        添&nbsp&nbsp加&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp                                          
        &nbsp&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp&nbsp                                             
        <input type="radio" name="choice" value="deleone" >                                   
        删&nbsp&nbsp除&nbsp&nbsp </td>                                                        
    </TR>                                                                                     
    <TR>                                                                                      
      <TD height=20 align=center>                                                             
        <INPUT type=submit name=Ok value=" 提交 " class=myBlack>                   
        <INPUT type=reset name=Back value=" 还原 " class=myBlack>                             
      </TD>                                                                                   
    </TR>                                                                                     
                                                                                              
  </TABLE>                                                                                    
</FORM>                                                                                       
<DIV class=myGreen align=center>                                                              
    <? echo $COPYRIGHT; ?>                                                                    
</DIV>                                                                                        
<BR>                                                                                          
                                                                                              
</BODY>                                                                                       
</HTML>                                       
2.   survey_begin.php                                            
<html>                                                                 
                                                                       
<!--网页的题头-->                                                      
<head>                                                                 
   <!-- HTML结构中的标题部分 -->                                       
   <title>                                                             
       网上调查                                                        
   </title>                                                            
   <meta http-equiv=content-type content="text/html; charset=gb2312">  
</head>                                                                
                                                                       
<!--正文的开始,并设置了背景图像-->                                    
<body  background="images/st.jpg" >                                    
<!--PHP程序的开始-->                                                   
  <?                                                                   
  /********************************                                    
  *运行一个外部的程序             *                                    
  *其作用是定义一些常用的变量     *                                    
  *并进行和goldenwind数据库的连接 *                                    
  *********************************/                                   
  include "common.inc.php";                                            
                                                                       
  //查询数据库中是否有调查的项目                                       
  $survey_check = "select title from survey";                          
  $check_result = mysql_query($survey_check)                           
    or die("不能进行网上调查。");                                      
  $check_num = mysql_num_rows($check_result);                          
                                                                       
  //如果没有正在进行的调查,则报错                                     
  if ($check_num == 0)                                                 
  {                                                                    
    header("Location: login_error.php?error=现在没有网上调查!\n");    
  }                                                                    
  else                                                                 
  {                                                                    
   //显示广告,可以是动态GIF格式                                       
    include "ad.php";                                                  
                                                                       
  /********************************                                    
  *显示本网页的大标题             *                                    
  *它随着日期中年月的变化而变化   *                                    
  *********************************/                                   
    echo "<p align=center>";                                           
    echo "  <font size=5 color=red >";                                 
    echo  date(Y)."年".date(m)."月社区调查的内容是:";                 
    echo "  </font>";                                                  
    echo "</p>";                                                       
                                                                       
    echo "<hr color=red>     ";                                        
    echo "<p><p><p><p><p>";                                            
                                                                       
    //变量$n用来记录每个调查的序号                                     
    $n=1;                                                              
    $next=" [url]http://localhost/survey.php?title[/url]=";                        
                                                                       
    $result = mysql_query($survey_check)                               
        or die("不能进行网上调查。");                                  
  /********************************                                    
  *在WHILE循环中依次取出数据库表  *                                    
  *中的网上调查项,并把每一项做成 *                                    
  *一个超链接                     *                                    
  *********************************/                                   
    while ($row=mysql_fetch_array($result))                            
    {                                                                  
    //在网页中加入空白的符号,控制显示的位置                           
       for ($i=1;$i<15;$i++)                                           
          echo "&nbsp";                                                
    //显示生成的超链接                                                 
       echo "<A href=\"".$next.$row["title"]                           
            ."\">".$n.'.&nbsp&nbsp&nbsp&nbsp'                          
            . $row["title"]."</a><p><p><p>\n";                         
    //每次循环把序号加一                                               
       $n++;                                                           
     }                                                                 
   }                                                                   
   //定义一些CSS的显示类                                               
   include "header.inc.php"   ;                                        
   ?>                                                                  
                                                                       
<!--显示版权信息-->                                                    
  <DIV class=myGreen align=center>                                     
      <? echo $COPYRIGHT; ?>                                           
  </DIV>                                                               
</body>                                                                
                                                                       
</html>  









本文转自 牛海彬 51CTO博客,原文链接:http://blog.51cto.com/newhappy/76894,如需转载请自行联系原作者
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
存储 算法 PHP
唯一ID生成原理与PHP实现-雪花算法
唯一ID生成原理与PHP实现-雪花算法
654 0
唯一ID生成原理与PHP实现-雪花算法
|
缓存 移动开发 NoSQL
php结合redis实现高并发下的抢购、秒杀功能的实例
php结合redis实现高并发下的抢购、秒杀功能的实例
254 0
|
PHP
github与gitee代码自动同步到服务器实现PHP项目自动部署webhooks
github与gitee代码自动同步到服务器实现PHP项目自动部署webhooks
513 0
github与gitee代码自动同步到服务器实现PHP项目自动部署webhooks
|
网络协议 Linux 网络安全
php实现websocket实时消息推送
php实现websocket实时消息推送
528 0
php实现websocket实时消息推送
|
PHP
php实现数字格式化,数字每三位加逗号的功能函数169856420=&gt;169,856,420
php实现数字格式化,数字每三位加逗号的功能函数169856420=&gt;169,856,420
213 0
|
PHP
PHP实现Workerman实例 高性能PHP Socket即时通讯框架
PHP实现Workerman实例 高性能PHP Socket即时通讯框架
421 0
|
消息中间件 PHP Windows
PHP实现php-amqplib/php-amqplib实例RabbitMq
PHP实现php-amqplib/php-amqplib实例RabbitMq
251 0
|
XML 移动开发 JSON
PHP使用yansongda/pay实现支付宝和微信的支付
PHP使用yansongda/pay实现支付宝和微信的支付
1077 0
|
NoSQL PHP Redis
PHP结合redis实现点赞功能
PHP结合redis实现点赞功能
142 0
|
消息中间件 缓存 JSON
PHP实现think-queue介绍
PHP实现think-queue介绍
425 0