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

开发者社区> 老牛的博客> 正文

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

简介: //createsurvey.sql CREATE TABLE survey (  title  varchar(60) NOT NULL,  totalfield    int(1),  o...
+关注继续查看

//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="http://localhost/survey.php?title=";                       
                                                                      
    $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>                                                               

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

相关文章
oracl使用DataBase Configuration Assistant创建、删除数据库
原文:oracl使用DataBase Configuration Assistant创建、删除数据库可以使用DataBase Configuration Assistant来创建一个心得数据库。Database Configuration Assistant简称是DBCA,是创建、配置以及管理数据库的一个工具。
1212 0
创建SSIS包—建立端到端的package
通过基本task和transforms的学习,现在可以转入到SSIS实际应用。建立端到端的package这个系列中首先讲解将一系列的文件数据导入到SQL Server中的方法,然后添加一些复杂转换,最后将看到如何在package中处理错误和动态地创建package。
820 0
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
3956 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
MySQL---数据库从入门走向大神系列(十三)-BasicDataSource创建DataSource(DBCP连接池配置)
DBCP(DataBase connection pool),数据库连接池。是 apache 上的一个 java 连接池项目,也是 tomcat 使用的连接池组件。单独使用dbcp需要2个包:commons-dbcp.jar,commons-pool.jar由于建立数据库连接是一个非常耗时耗资源的行为,所以通过连接池预先同数据库建立一些连接,放在内存中,应用程序需要建立数据库连接时直接到连接池中申请一个就行,用完后再放回去。
937 0
创建SinaSAE云账号创建和发布基于SVN代码管理的PHP空工程
1、使用Sina微博账号登录,进入【新浪云控制台】 2、选择【云应用SAE】界面,选择【创建新应用】 3、点击【继续创建】,进入应用信息编辑界面     依次编辑“二级域名”“应用程序名”,再点【运行环境】中的【PHP空应用】,再点左下角的【创建应用】完成应用创建。
815 0
+关注
老牛的博客
喜欢研究数据库维护,互联网运营的朋友,可以加我QQ:52234858
327
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
文娱运维技术
立即下载
《SaaS模式云原生数据仓库应用场景实践》
立即下载
《看见新力量:二》电子书
立即下载