PHP的bbs实现之四--创建调查-阿里云开发者社区

开发者社区> 余二五> 正文

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

简介:
+关注继续查看
//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,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
创建SSIS包—建立端到端的package
通过基本task和transforms的学习,现在可以转入到SSIS实际应用。建立端到端的package这个系列中首先讲解将一系列的文件数据导入到SQL Server中的方法,然后添加一些复杂转换,最后将看到如何在package中处理错误和动态地创建package。
820 0
php归档格式:phar文件详解(创建、使用、解包还原提取)
转载一篇,突然遇到一个冷知识,phar的东东,貌似和jar、war是一种鬼。 重点使用一下下面这个东东,就能解包出来东东了。 $phar = new Phar('lib/yunke.phar', 0);   $phar->setAlias ( "yun.
885 0
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
3959 0
PolarDB-X 1.0-API参考-1.0(2017版本)-数据库管理类 API-创建数据库
功能描述 创建 DRDS 数据库。该接口只是向控制台提交了一个创建分布式数据库的任务,接入方需要依据 DescribeDrdsDB 接口(查询数据库信息的接口)的返回结果来判断分布式数据库是否创建成功。
12 0
mybatis session创建过程(2)
session创建过程  在mybatis的常规用法当中,通过sqlSessionFactory.openSession()来创建SqlSession对象,这里的sqlSessionFactory就是在解析配置后生成的SqlSession的工厂。
847 0
阿里云服务器如何登录?阿里云服务器的三种登录方法
购买阿里云ECS云服务器后如何登录?场景不同,阿里云优惠总结大概有三种登录方式: 登录到ECS云服务器控制台 在ECS云服务器控制台用户可以更改密码、更换系.
5684 0
phpmyadmin上在某数据库里创建函数
改那个PHP项目加了个功能,本地MYSQL里添加了一个函数了,现在要转到服务器上,然后服务器上的MYSQL只能通过PHPMYADMIN网页操作的,在网页上SQL里输入创建函数的语句, 结果报错了:this function has none of DETERMINISTIC 查了一下是这个原因:https://www.
691 0
创建SSIS包—ETL中典型的数据清洗
前面我们熟悉了很多ELT任务,这一个节来讨论复杂点的数据清洗。这里我们要使用的数据源是.dat文件,这种文件在大型主机上,或者是比较老旧的应用系统中非常常见。这个例子的情景是一个信用卡公司,目前正着手于拓展Florida州新成立的一些公司的业务。
724 0
+关注
12613
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
文娱运维技术
立即下载
《SaaS模式云原生数据仓库应用场景实践》
立即下载
《看见新力量:二》电子书
立即下载