投票管理程序


Posted in PHP onOctober 09, 2006

投票管理程序

表结构
CREATE TABLE poll(Poll_Id INT (11) not null AUTO_INCREMENT,Poll_Name char(50) ,Poll_Del INT (10) DEFAULT '0' , PRIMARY KEY (Poll_Id))   

CREATE TABLE pollsele(Pollsele_Id INT (11) not null AUTO_INCREMENT,Pollsele_Name char(50) ,Poll_Del INT (10) DEFAULT '0' , Pollsele_poll_Id INT (10) ,pollsele_num int (10), PRIMARY KEY (Pollsele_Id))   
-------------------------------------------------------------------------------------------------
poll.php   //主程序

<?     $db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);
$sql="select poll_id,Poll_Name from poll where poll_del='1'";
@$result = mysql_query($sql);

      $myrow=mysql_fetch_row($result);
     echo "<table align=center bgcolor=aabbcc width=250 hight=450 border=0 style='border:1px solid rgb(0,0,0)'>";
         echo "<td align=center bgcolor=99aabb style='border:1px solid rgb(255,255,255)'>";

      echo "$myrow[1]";

       $sql="select Pollsele_Name,pollsele_poll_id from pollsele where pollsele_del='0' and pollsele_poll_id='$myrow[0]'";
@$result = mysql_query($sql);
  echo "<FORM ACTION='pollsee.php?poll_id=$myrow[0]' METHOD='post' target=_blank>";
     echo "<p align=center>";
   while($myrow=mysql_fetch_row($result))
   {

   echo "<input type='radio' name=toupiao value='$myrow[0]'>$myrow[0]";
     echo " ";                                          }
   echo "<br>";  echo "<br>";
  echo "<input type=submit name=submit value='投票' >";

   echo "</p>";
  echo "</form>";      echo "</td>";
       echo "</table>";
   mysql_close();
    echo "<br>";
    echo "<p align=right>";
   echo "<a href=poll_input>管理</a>"; echo "</p>";     ?>
-----------------------------------------------------------------------
poll_input.php  //添加主题

<?        $db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);
       $sql="select poll_id,poll_name,poll_del from poll";
              echo "<table width=300 hight=560 bgcolor=aabbcc align=center style='border:1px solid rgb(0,0,0)'>";
             $result=mysql_query($sql);
             while($my=mysql_fetch_row($result))
            {

    echo "<tr>";echo "<td align=center width=50 bgcolor=99aabb style='border: 1px solid rgb(255,255,255)'>";echo $my[0];echo "</td>";
              echo "<td align=center width=200 bgcolor=99aabb style='border: 1px solid rgb(255,255,255)'><a href=pollsele.php?id=$my[0]>$my[1]</a></td>";
    echo "<td align=center width=50 bgcolor=99aabb style='border: 1px solid rgb(255,255,255)'>";echo $my[2];echo "</td>";
                 echo "</tr>";

                  }    echo "</table>";
                   ?>
<html>
<head>
  <?

           if($submit2!="添加")
             { echo "<p align=center>";
             echo "<FORM ACTION='poll_input.php' METHOD='post'>";

        echo "<font color=004080>主题:</font>";
       echo "<input type=text name=title size=30 value=''>";

      echo "<input type=submit name=submit2 value='添加'>";
                    echo "</p>";
           echo"</form>";   }

else
      {$db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);
       $sql="select poll_name from poll where poll_name='$title'";
             mysql_query($sql);

$sql="insert into poll values('','$title','')";
mysql_query($sql);
mysql_close();
echo "<META HTTP-EQUIV=REFRESH CONTENT='1; URL=poll_input.php'>";  }
           if($submit1!="有效"&&$submit3!="删除")
           {  echo "<p align=center>";
           echo "<FORM ACTION='poll_input.php' METHOD='post'>";
           echo "<font color=004080>设置主题:</font>";
   echo "<select name='sele' size=1>";
         $db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);
$sql="select Poll_Id from poll";
$result = mysql_query($sql);
mysql_close();
while($myrow=mysql_fetch_row($result))
{ echo "<option value='$myrow[0]'>$myrow[0]";}

   echo "</select>";
     echo "<input type=submit name=submit1 value='有效'>";
        echo "<input type=submit name=submit3 value='删除'>";
       echo "</p>";
echo "</FORM>";

           }
           else
           {
              if($submit1=="有效")
              {
           $db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);

$sql="update poll set Poll_Del='0'";
$result = mysql_query($sql);

  $sql="update poll set Poll_Del='1' where poll_id='$sele'";
$result = mysql_query($sql);

mysql_close();
echo "<META HTTP-EQUIV=REFRESH CONTENT='1; URL=poll_input.php'>";      }
    else
    {   $db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);
$sql="delete from poll where poll_id='$sele'";
$result = mysql_query($sql);
$sql="delete from pollsele where pollsele_poll_id='$sele'";
mysql_query($sql);
mysql_close();
echo "<META HTTP-EQUIV=REFRESH CONTENT='1; URL=poll_input.php'>";      }

}
?>
--------------------------------------------------------------------
pollsele.php  //添加选项

<?        $db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);
       $sql="select pollsele_id,pollsele_name,pollsele_del,pollsele_num from pollsele where pollsele_poll_id='$id'";
              echo "<table width=300 hight=560 align=center bgcolor=aabbcc style='border:1px solid rgb(0,0,0)' >";
             @$result=mysql_query($sql);
             while($my=mysql_fetch_row($result))
            {

    echo "<tr>";echo "<td align=center width=50 bgcolor=99aabb  style='border: 1px solid rgb(255,255,255)'>";echo $my[0];echo "</td>";
              echo "<td align=center width=200 bgcolor=99aabb  style='border: 1px solid rgb(255,255,255)'>$my[1]</td>";
    echo "<td align=center width=50 bgcolor=99aabb  style='border: 1px solid rgb(255,255,255)'>";echo $my[2];echo "</td>";
         echo "<td align=center width=50 bgcolor=99aabb  style='border: 1px solid rgb(255,255,255)'>";echo $my[3];echo "</td>";
                 echo "</tr>";

                  }    echo "</table>";
                   ?>
<html>
<head>
  <?

           if($submit2!="添加")
             {     echo "<p align=center>";
             echo "<FORM ACTION='pollsele.php?id=$id' METHOD='post'>";

        echo "<font color=004080>选项:</font></td>";
       echo "<input type=text name=title size=30 value=''>";

      echo "<input type=submit name=submit2 value='添加'>";
                    echo "</p>";
           echo"</form>";   }

else
      {$db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);

$sql="insert into pollsele values('','$title','','$id','')";
mysql_query($sql);
mysql_close();
echo "<META HTTP-EQUIV=REFRESH CONTENT='1; URL=pollsele.php?id=$id'>";  }
           if($submit1!="有效"&&$submit3!="无效")
           {  echo "<p align=center>";
           echo "<FORM ACTION='pollsele.php?id=$id' METHOD='post'>";
            echo "<font color=004080>设置选项:</font>";
   echo "<select name='sele' size=1>";
         $db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);
$sql="select Pollsele_Id from pollsele where pollsele_poll_id='$id'";
$result = mysql_query($sql);
mysql_close();
while($myrow=mysql_fetch_row($result))
{ echo "<option value='$myrow[0]'>$myrow[0]";}

   echo "</select>";
     echo "<input type=submit name=submit1 value='有效'>";
        echo "<input type=submit name=submit3 value='无效'>";
      echo "</p>";
echo "</FORM>";

           }
           else
           { $db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);
      if ($submit1=="有效")
      {
    $sql="update pollsele set Pollsele_Del='0' where pollsele_id='$sele'";
$result = mysql_query($sql);}
else
{
$sql="update pollsele set Pollsele_Del='1' where pollsele_id='$sele'";
$result = mysql_query($sql);   }
mysql_close();
echo "<META HTTP-EQUIV=REFRESH CONTENT='1; URL=pollsele.php?id=$id'>";      }

?>
----------------------------------------------------------------------
pollsee.php  //投票结果

<?       if ($toupiao!=""){
$db =mysql_connect("localhost", "root","391450");
mysql_select_db("class",$db);
  $sql="select Pollsele_Name,pollsele_num from pollsele where pollsele_name='$toupiao'";
@$result = mysql_query($sql);
  $myrow=mysql_fetch_row($result);
  $poll_num=$myrow[1];
  $poll_num=$poll_num+1;
$sql="update pollsele set Pollsele_num='$poll_num' where pollsele_name='$toupiao'";
mysql_query($sql);

    $sql="select Poll_Name from poll where poll_id='$poll_id'";
@$result = mysql_query($sql);
     $title=mysql_fetch_row($result);
       echo "<p align=center>";
      echo $title[0]; echo "</p>";
      echo "<br>";
       $sql="select Pollsele_Name,pollsele_num from pollsele where pollsele_del='0' and pollsele_poll_id='$poll_id'";
@$result = mysql_query($sql);
      echo "<table align=center bgcolor=aabbcc style='border:1px solid rgb(0,0,0)'>";
  while($myrow=mysql_fetch_row($result))
  {   echo "<tr>"; echo "<td width=150 bgcolor=99aabb style='border:1px solid rgb(255,255,255)'>";
  echo $myrow[0];echo "</td><td width=50 bgcolor=99aabb style='border:1px solid rgb(255,255,255)'>";echo $myrow[1]; echo "</td></tr>";} echo "</table>";  }
  else
  {echo "<font color=red>你不能投空票!!!</font>";}

    ?>  

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】    

PHP 相关文章推荐
信用卡效验程序
Oct 09 PHP
PhpMyAdmin中无法导入sql文件的解决办法
Jan 08 PHP
关于初学PHP时的知识积累总结
Jun 07 PHP
thinkphp实现图片上传功能分享
Mar 04 PHP
PHPUnit安装及使用示例
Oct 29 PHP
php中Socket创建与监听实现方法
Jan 05 PHP
php 5.6版本中编写一个PHP扩展的简单示例
Jan 20 PHP
WordPress中访客登陆实现邮件提醒的PHP脚本实例分享
Dec 14 PHP
PHP中include/require/include_once/require_once使用心得
Aug 28 PHP
thinkPHP引入类的方法详解
Dec 08 PHP
php curl常用的5个经典例子
Jan 20 PHP
PHP中$GLOBALS与global的区别详解
Mar 21 PHP
用PHP和ACCESS写聊天室(九)
Oct 09 #PHP
用PHP和ACCESS写聊天室(八)
Oct 09 #PHP
用PHP和ACCESS写聊天室(七)
Oct 09 #PHP
一个简单实现多条件查询的例子
Oct 09 #PHP
用PHP和ACCESS写聊天室(十)
Oct 09 #PHP
php生成EXCEL的东东
Oct 09 #PHP
一个取得文件扩展名的函数
Oct 09 #PHP
You might like
php面向对象全攻略 (十二) 抽象方法和抽象类
2009/09/30 PHP
php中获取关键词及所属来源搜索引擎名称的代码
2011/02/15 PHP
提升PHP性能的21种方法介绍
2013/06/25 PHP
php无限遍历文件夹示例分享
2014/03/04 PHP
php实现中文字符截取防乱码方法汇总
2015/04/29 PHP
php+curl 发送图片处理代码分享
2015/07/09 PHP
PHP防止刷新重复提交页面的示例代码
2015/11/11 PHP
PHP生成各种常见验证码和Ajax验证过程
2016/01/10 PHP
通过JS获取用户本地图片路径并显示的代码
2012/02/16 Javascript
jquery 文本上下无缝滚动,鼠标放上去就停止 小例子
2013/06/05 Javascript
javascript使用appendChild追加节点实例
2015/01/12 Javascript
JS 作用域与作用域链详解
2015/04/07 Javascript
AngularJS 使用$sce控制代码安全检查
2016/01/05 Javascript
在微信、支付宝、百度钱包实现点击返回按钮关闭当前页面和窗口的方法
2016/08/05 Javascript
jQuery解析返回的xml和json方法详解
2017/01/05 Javascript
vue.js与后台数据交互的实例讲解
2018/08/08 Javascript
jQuery实现经典的网页3D轮播图封装功能【附源码下载】
2019/02/15 jQuery
javascript刷新父页面方法汇总详解
2019/10/10 Javascript
详解Python3.1版本带来的核心变化
2015/04/07 Python
Python 搭建Web站点之Web服务器网关接口
2016/11/06 Python
python用reduce和map把字符串转为数字的方法
2016/12/19 Python
python判断一个集合是否为另一个集合的子集方法
2018/05/04 Python
python实现黑客字幕雨效果
2018/06/21 Python
python版opencv摄像头人脸实时检测方法
2018/08/03 Python
python生成以及打开json、csv和txt文件的实例
2018/11/16 Python
如何更优雅地写python代码
2019/07/02 Python
微信小程序python用户认证的实现
2019/07/29 Python
导致python中import错误的原因是什么
2020/07/01 Python
面向新手解析python Beautiful Soup基本用法
2020/07/11 Python
如何基于Python实现word文档重新排版
2020/09/29 Python
Europcar意大利:汽车租赁
2019/07/07 全球购物
煤矿班组长岗位职责
2013/12/29 职场文书
国庆节文艺活动方案
2014/02/03 职场文书
食品安全责任书
2014/04/15 职场文书
海洋天堂观后感
2015/06/05 职场文书
昆虫记读书笔记
2015/06/26 职场文书