投票管理程序


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 相关文章推荐
php 魔术函数使用说明
Feb 21 PHP
phpMyadmin 用户权限中英对照
Apr 02 PHP
PHP 动态随机生成验证码类代码
Apr 09 PHP
PHP入门学习笔记之一
Oct 12 PHP
php设计模式 State (状态模式)
Jun 26 PHP
php获取文章上一页与下一页的方法
Dec 01 PHP
PHP+Ajax实现无刷新分页实例详解(附demo源码下载)
Apr 07 PHP
详解PHP中websocket的使用方法
Sep 15 PHP
自制PHP框架之模型与数据库
May 07 PHP
PHP依赖注入(DI)和控制反转(IoC)详解
Jun 12 PHP
PHP删除数组中指定值的元素常用方法实例分析【4种方法】
Aug 21 PHP
PHP的mysqli_set_charset()函数讲解
Jan 23 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
中东人咖啡哲学
2021/03/03 咖啡文化
基于session_unset与session_destroy的区别详解
2013/06/03 PHP
为PHP安装imagick时出现Cannot locate header file MagickWand.h错误的解决方法
2014/11/03 PHP
php中ob_get_length缓冲与获取缓冲长度实例
2014/11/20 PHP
php模拟用户自动在qq空间发表文章的方法
2015/01/07 PHP
php计算两个日期相差天数的方法
2015/03/14 PHP
PHP中is_file()函数使用指南
2015/05/08 PHP
CodeIgniter 完美解决URL含有中文字符串
2016/05/13 PHP
php中替换字符串函数strtr()和str_repalce()的用法与区别
2016/11/25 PHP
PHP判断文件是否被引入的方法get_included_files用法示例
2016/11/29 PHP
PHP设计模式之装饰器(装饰者)模式(Decorator)入门与应用详解
2019/12/13 PHP
tp5.1 框架数据库高级查询技巧实例总结
2020/05/25 PHP
phpStudy vscode 搭建debug调试的教程详解
2020/07/28 PHP
不错的JS中变量相关的细节分析
2007/08/13 Javascript
分享20款好玩的jQuery游戏
2011/04/17 Javascript
Jquery选中或取消radio示例
2013/09/29 Javascript
jQuery事件绑定和委托实例
2014/11/25 Javascript
vue-resourse将json数据输出实例
2017/03/08 Javascript
EasyUI在Panel上动态添加LinkButton按钮
2017/08/11 Javascript
vue父组件向子组件动态传值的两种方法
2017/11/11 Javascript
微信小程序自定义组件之可清除的input组件
2018/07/17 Javascript
layui 优化button按钮和弹出框的方法
2018/08/15 Javascript
Python 错误和异常小结
2013/10/09 Python
Python urlopen()函数 示例分享
2014/06/12 Python
一张图带我们入门Python基础教程
2017/02/05 Python
Python实现的多线程http压力测试代码
2017/02/08 Python
利用python操作SQLite数据库及文件操作详解
2017/09/22 Python
Python DataFrame设置/更改列表字段/元素类型的方法
2018/06/09 Python
对Python中实现两个数的值交换的集中方法详解
2019/01/11 Python
python面试题小结附答案实例代码
2019/04/11 Python
tensorflow pb to tflite 精度下降详解
2020/05/25 Python
如何使用python记录室友的抖音在线时间
2020/06/29 Python
基于PyInstaller各参数的含义说明
2021/03/04 Python
CSS3的RGBA中关于整数和百分比值的转换
2015/08/04 HTML / CSS
Java程序员综合测试题
2014/04/25 面试题
2015年体育教学工作总结
2015/05/20 职场文书