投票管理程序


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 相关文章推荐
解析thinkphp中的导入文件标签
Jun 20 PHP
PHP删除数组中特定元素的两种方法
Jul 02 PHP
Smarty foreach控制循环次数的实现详解
Jul 03 PHP
更改localhost为其他名字的方法
Feb 10 PHP
php自动加载autoload机制示例分享
Feb 20 PHP
PHP Smarty模版简单使用方法
Mar 30 PHP
php+MySQL实现登录时验证登录名和密码是否正确
May 10 PHP
php代码检查代理ip的有效性
Aug 19 PHP
PHP读取大文件的几种方法介绍
Oct 27 PHP
PHP安装memcache扩展的步骤讲解
Feb 14 PHP
PHP 进程池与轮询调度算法实现多任务的示例代码
Nov 26 PHP
PHP获取php,mysql,apche的版本信息及更多服务器信息
Mar 09 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获取指定日期所在月的开始日期与结束日期
2013/08/01 PHP
学习php分页代码实例
2013/10/24 PHP
php遍历删除整个目录及文件的方法
2015/03/13 PHP
PHP实现的XML操作类【XML Library】
2016/12/29 PHP
PHP四种排序算法实现及效率分析【冒泡排序,插入排序,选择排序和快速排序】
2018/04/27 PHP
jquery文本框中的事件应用以输入邮箱为例
2014/05/06 Javascript
jquery如何获取元素的滚动条高度等实现代码
2015/10/19 Javascript
jquery简单插件制作(fn.extend)完整实例
2016/05/24 Javascript
JavaScript遍历求解数独问题的主要思路小结
2016/06/12 Javascript
微信小程序 图片加载(本地,网路)实例详解
2017/03/10 Javascript
vue 和vue-touch 实现移动端左右导航效果(仿京东移动站导航)
2017/04/22 Javascript
JS触摸与手势事件详解
2017/05/09 Javascript
JavaScript制作简单的框选图表
2017/05/15 Javascript
ES6 javascript中class类的get与set用法实例分析
2017/10/30 Javascript
Angularjs按需查询实例代码
2017/10/30 Javascript
微信小程序按顺序同步执行的两种方式
2019/12/20 Javascript
javascript设计模式 ? 装饰模式原理与应用实例分析
2020/04/14 Javascript
解决vue动态路由异步加载import组件,加载不到module的问题
2020/07/26 Javascript
vue 解决在微信内置浏览器中调用支付宝支付的情况
2020/11/09 Javascript
在Python中使用SimpleParse模块进行解析的教程
2015/04/11 Python
在Python中操作文件之seek()方法的使用教程
2015/05/24 Python
python运行时间的几种方法
2016/06/17 Python
Python使用自带的ConfigParser模块读写ini配置文件
2016/06/26 Python
python anaconda 安装 环境变量 升级 以及特殊库安装的方法
2017/06/21 Python
Python正则捕获操作示例
2017/08/19 Python
python实现ip代理池功能示例
2019/07/05 Python
手把手教你pycharm专业版安装破解教程(linux版)
2019/09/26 Python
Python request操作步骤及代码实例
2020/04/13 Python
Vs Code中8个好用的python 扩展插件
2020/10/12 Python
护理专业毕业生自荐信范文
2014/01/05 职场文书
小学生红领巾广播稿
2014/01/21 职场文书
工厂车间标语
2014/06/19 职场文书
颐和园英文导游词
2015/01/30 职场文书
元旦晚会开场白
2015/05/29 职场文书
聊聊mysql都有哪几种分区方式
2022/04/13 MySQL
Python万能模板案例之matplotlib绘制甘特图
2022/04/13 Python