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

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: //createsurvey.sqlCREATE 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>                                                               

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
SQL PHP 数据安全/隐私保护
|
SQL PHP 数据库
|
SQL PHP 数据库
PHP的bbs实现之一
0.sql CREATE TABLE user_log (  log_id int(10) NOT NULL auto_increment,  nicker        varchar(20...
705 0
|
SQL 前端开发 PHP
PHP的bbs实现之三
 邮件发送功能实现: sql语句: CREATE TABLE ourmail2 (  email_addr  varchar(40) NOT NULL,  create_time  var...
1009 0
|
2月前
|
安全 关系型数据库 MySQL
PHP与MySQL交互:从入门到实践
【9月更文挑战第20天】在数字时代的浪潮中,掌握PHP与MySQL的互动成为了开发动态网站和应用程序的关键。本文将通过简明的语言和实例,引导你理解PHP如何与MySQL数据库进行对话,开启你的编程之旅。我们将从连接数据库开始,逐步深入到执行查询、处理结果,以及应对常见的挑战。无论你是初学者还是希望提升技能的开发者,这篇文章都将为你提供实用的知识和技巧。让我们一起探索PHP与MySQL交互的世界,解锁数据的力量!
|
2月前
|
NoSQL 关系型数据库 MySQL
不是 PHP 不行了,而是 MySQL 数据库扛不住啊
【9月更文挑战第8天】这段内容讨论了MySQL在某些场景下面临的挑战及其原因,并指出这些问题不能完全归咎于MySQL本身。高并发读写压力、数据量增长以及复杂查询和事务处理都可能导致性能瓶颈。然而,应用程序设计不合理、系统架构不佳以及其他数据库选择和优化策略不足也是重要因素。综合考虑这些方面才能有效解决性能问题,而MySQL通过不断改进和优化,仍然是许多应用场景中的可靠选择。
124 9
|
3月前
|
存储 SQL 关系型数据库
PHP与MySQL交互的奥秘
【8月更文挑战第29天】在编程的世界里,PHP和MySQL就像是一对默契的舞伴,共同演绎着数据的交响曲。本文将带你探索它们之间的互动,从连接数据库到执行查询,再到处理结果,每一步都充满了节奏与和谐。我们将一起走进这段代码的旅程,感受数据流动的魅力。