PHP+MySql简单投票系统代码

本文提供了一个使用PHP和MySQL构建的简单投票系统的前后台代码示例,包括用户投票、查看结果和后台管理功能。涉及的文件包括index.php、result.php、public.js、conn.php以及样式表和数据库交互。
摘要由CSDN通过智能技术生成


http://hi.baidu.com/devin_he/blog/item/8bbaf273574111198701b090.html


PHP+MySql简单投票系统代码(包括前台、后台)
 前台代码:
index.php

<?php include_once("include/conn.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="js/public.js"></script>
</head>
<?php
$ObjID="4";
$Sql="select * from tobject where ID='".$ObjID."'";
$Result=mysql_query($Sql);
$Arr=mysql_fetch_array($Result);
$OJBName=$Arr['OJBName'];
$SType=$Arr['SType'];
?>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="616" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
    <tr>
      <td width="521" class="font1 td1">题目:<?php echo $OJBName?>
      <input name="SType" type="hidden" id="SType" value="<?php echo $SType?>" />
      <input name="opt" type="hidden" id="opt" />
      <input name="ObjID" type="hidden" id="ObjID" value="<?php echo $ObjID?>" /></td>
      <td width="80" align="center" class="font2 td1">[<a href="javascript:lookresult('result.php',document.form1,'look');">查看结果</a>]</td>
    </tr>
    <tr>
      <td colspan="2" bgcolor="#FFFFFF" class="font2">
   <?php
   $Sql="select * from tselect where ObjID='".$ObjID."'";
   $Result=mysql_query($Sql);
   while($Arr=mysql_fetch_array($Result))
     {
   if($SType=="0")
    {
    echo "<input type="radio" name="Sel" value="".$Arr['ID']."" /> ".$Arr['SName']."<br> ";
       }
   elseif($SType=="1")
    {
    echo "<input name="SelArr[]" type="checkbox" id="SelArr" value="".$Arr['ID']."" /> ".$Arr['SName']."<br> ";
    }
   }
   ?>   </td>
    </tr>
</table>
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td height="41" align="center"><input type="button" name="Submit" value="提交" οnclick="lookresult('result.php',document.form1,'vote');" />
     
          <input type="reset" name="Submit2" value="重置" /></td>
    </tr>
</table>
</form>
</body>
</html>

result.php

<?php include_once("include/conn.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<?php
$IP=$_SERVER["REMOTE_ADDR"];
$SType=$_POST['SType'];
$Sel=$_POST['Sel'];
$SelArr=$_POST['SelArr'];
$opt=$_POST['opt'];
$ObjID=$_POST['ObjID'];
$Sql="select count(1) as IPNum from IPTable where IP='".$IP."' and ObjID='".$ObjID."'";
$Result=mysql_query($Sql);
$Arr=mysql_fetch_array($Result);
if($opt=="vote")
{
if($Arr['IPNum']<=0)
    {
    if($SType=="0")
      {
   $Sql="update tselect set `Num`=`Num`+1 where ID='".$Sel."'";
   if(mysql_query($Sql))
     {
     mysql_query("insert into IPTable (IP,ObjID) values ('".$IP."','".$ObjID."')");
     echo "<script>alert('投票成功,感谢您的参与!');</script>";
     }
   else
     {
     echo "<script>alert('投票失败,请您重新投票,感谢您的参与!');</script>";
     }
   }
    elseif($SType=="1")
      {
   $Count=count($SelArr);
   for($i=0;$i<$Count;$i++)
     {
     $SqlStr.=" ID=".$SelArr[$i]." or ";
     }
   $SqlStr=substr($SqlStr,0,strlen($SqlStr)-4);
   $Sql="update tselect set `Num`=`Num`+1 where ".$SqlStr;
   if(mysql_query($Sql))
     {
     mysql_query("insert into IPTable (IP,ObjID) values ('".$IP."','".$ObjID."')");
     echo "<script>alert('投票成功,感谢您的参与!');</script>";
     }
   else
     {
     echo "<script>alert('投票失败,请您重新投票,感谢您的参与!');</script>";
     }
   }
    }
else
    {
    echo "<script>alert('您已经投过票,不需要再次投票!');</script>";
    }
}

$Sql="select

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值