投票管理程序


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安全编程之加密功能
Oct 09 PHP
dedecms模板标签代码官方参考
Mar 17 PHP
Bo-Blog专用的给Windows服务器的IIS Rewrite程序
Aug 26 PHP
php 删除无限级目录与文件代码共享
Nov 22 PHP
php写的带缓存数据功能的mysqli类
Sep 06 PHP
无刷新动态加载数据 滚动条加载适合评论等页面
Oct 16 PHP
Eclipse的PHP插件PHPEclipse安装和使用
Jul 20 PHP
php5.3提示Function ereg() is deprecated Error问题解决方法
Nov 12 PHP
Swoole-1.7.22 版本已发布,修复PHP7相关问题
Dec 31 PHP
nginx下安装php7+php5
Jul 31 PHP
PHP数据对象映射模式实例分析
Mar 29 PHP
php和redis实现秒杀活动的流程
Jul 17 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图片等比例缩放生成缩略图函数分享
2014/06/10 PHP
php实现的Cookies操作类实例
2014/09/24 PHP
PHP简单获取及判断提交来源的方法
2016/04/22 PHP
php json中文编码为null的解决办法
2016/12/14 PHP
innertext , insertadjacentelement , insertadjacenthtml , insertadjacenttext 等区别
2007/06/29 Javascript
JavaScript delete 属性的使用
2009/10/08 Javascript
javascript面向对象之Javascript 继承
2010/05/04 Javascript
详解Node.js串行化流程控制
2017/05/04 Javascript
jQuery实现动态给table赋值的方法示例
2017/07/04 jQuery
官方推荐react-navigation的具体使用详解
2018/05/08 Javascript
详解javascript 正则表达式之分组与前瞻匹配
2018/05/30 Javascript
在layui tab控件中载入外部html页面的方法
2019/09/04 Javascript
vant中的toast轻提示实现代码
2020/11/04 Javascript
[38:39]完美世界DOTA2联赛循环赛 IO vs GXR BO2第二场 11.04
2020/11/05 DOTA
在Python3中使用asyncio库进行快速数据抓取的教程
2015/04/02 Python
Python 实现简单的电话本功能
2015/08/09 Python
详解Python3中字符串中的数字提取方法
2017/01/14 Python
python/sympy求解矩阵方程的方法
2018/11/08 Python
Python学习笔记之Zip和Enumerate用法实例分析
2019/08/14 Python
Pycharm 安装 idea VIM插件的图文教程详解
2020/02/21 Python
有影响力的品牌之家:Our Social Collective
2019/06/08 全球购物
应聘医学检验人员自荐信
2013/09/27 职场文书
优秀中专生推荐信
2013/11/17 职场文书
企业管理毕业生求职信范文
2014/03/07 职场文书
医药营销个人求职信
2014/04/12 职场文书
《梅花魂》教学反思
2014/04/30 职场文书
煤矿安全承诺书
2014/05/22 职场文书
项目经理任命书
2014/06/04 职场文书
合作协议书范文
2014/08/20 职场文书
普通党员个人剖析材料
2014/10/08 职场文书
护理专业自我评价
2015/03/11 职场文书
无罪辩护词范文
2015/05/21 职场文书
新闻发布会新闻稿
2015/07/17 职场文书
幼儿教师三分钟演讲稿
2019/06/21 职场文书
竞选稿之小学班干部
2019/10/31 职场文书
sql中mod()函数取余数的用法
2021/05/29 SQL Server