分析:  
我们利用一个文件(data.dat)来存储投票栏目.每个栏目占据一行.  
这样一来,便可随意加入和减去想要投票的栏目.  
我们再利用一个文件(votes.dat)来存储我们的投票结果.  
并纪录最近一位投票者的IP地址,简单的防止一人多投.  
所以,您应该在该程序目录下自行建立两个文件data.dat和votes.dat  
程序运行过程部分  
程序运行时应该先有一个投票的HTML表单,等待投票.  
当有人在HTML表单上投票时,判断它的IP是否为最近一位投票者的IP,  
如果此人刚刚投过票,则两个值应该相等,显示"您已投过票了,谢谢您的参与!"   
如果此人没投过票,则两个值不等,将它的投票写入文件(votes.dat)   
(这里得到投票者的IP方法是:Web客户机在对服务器发送请求时需要提供一个表识,  
这个表识就存储在环境变量REMOTE_ADDR里,我们引用它就可以了.)  
最后是显示投票结果,通常我们是以"条形图表+百分数"来显示投票情况.  
所以,我们要选择一个颜色单一的矩形图形,以适应横向缩放的要求.   
-------------------------------------------------------------------------------- 

程序代码部分 可下载程序代码
  //投票栏目存储文件,您可更改文件名  
$data="data.dat";
//投票结果储存文件   
$votes="votes.dat";
//用以显示投票结果比例的图形文件名图形文件名,
//用单一颜色的矩形较好,方便投票结果横向缩放,
//自行上传到本程序目录下   
$path_img="vote.gif";
//投票标题  
$poll_name="您喜欢我的哪个栏目?";
// 以下部分不需改动 //
//打开投票栏目文件,并以数组的形式将全部内容存在变量$dataf中备用   
$dataf=file($data);
if ($go !=1)
{
//显示投票程序表单   
echo "<font color=red><i>$poll_name</i></font><br>n";
echo "<form method=post>";
for ($i=0; $i<=count($dataf)-1; $i++)
{
echo "<input type=radio name="vote" value="$i"> $dataf[$i]<br>n"; }
echo "<input type=hidden name=go value=1>";
echo "<p><input type=Submit value=投票>";
echo "</form>";
echo "<a href='vote.php?result=1&go=1'>查看结果</a>";
}
else
{
// $go==1 表示有人投票, // 现在将投票情况以另外一种方式从文件中读出 $file_votes=fopen($votes, "r");   
$line_votes=fgets($file_votes, 255);
fclose($file_votes);
// 并将数据按指定的字串切开,再将字串传回到阵列变量中   
$single_vote=explode("|", $line_votes);
//准备写入投票结果   
if ($result!=1)
{
//检查IP地址是否重复   
$file_votes=file($votes, "r");
if ($REMOTE_ADDR == $file_votes[1])
{
echo "<center><font color=red>您已投过票了,谢谢您的参与! </font>    </center>";
exit;
}
//如果IP不重复,则执行以下程序   
$ficdest=fopen($votes, "w");
for ($i=0; $i<=count($dataf)-1; $i++)
{
//判断投了那一个栏目   
if ($i == $vote)
{
$single_vote[$i]+=1;
}
//将数据写回文件   
fputs($ficdest, "$single_vote[$i]|");
}
//写入投票者IP   
fputs($ficdest, "n$REMOTE_ADDR");
fclose($ficdest);
$result=1; //投票成功  
}
//写入投票结果后并显示投票结果   
if ($result==1)
{ echo "<table cellpadding=10>";
for ($i=0; $i<=count($dataf)-1; $i++)
{
//取得投票总数  
$tot_votes+=$single_vote[$i];
}
for ($i=0; $i<=count($dataf)-1; $i++)
{
//计算百分比   
$stat[$i]=$single_vote[$i]/$tot_votes*100;
echo "<tr><td><li><font face=Verdana size=2>";
echo "$dataf[$i]</font></td><td align=left><font face=Verdana       size=2>";
echo "<img src="$path_img" height=10 width=$stat[$i] align=middle> ";
//输出百分数 printf("%.1f", "$stat[$i]");   
echo "%</font></td><td align=center><font face=Verdana size=2>"; //输出本栏目投票数   
echo "$single_vote[$i]</font>"; echo "</td></tr>";
}
echo "</table><p>";
echo "<font face=Verdana size=2>总投票数:$tot_votes </font>";
}
}
?>

                *********************************************
            *********************************************
        *********************************************
        *********************************************
        *********************************************

<?php
  $query="select * from tb_poll1 where tpzt='$lmlb'";
  $result=mysql_query($query);
  $myrow=mysql_fetch_array($result);
  $danxuan=$myrow[danxuan];
 if($danxuan=="单选"){

?>
  <table width="450" border="1" cellpadding="0" cellspacing="0" background="images/admin2.gif">
  <form name="form1" method="post" action="index_ok.php" enctype="multipart/form-data">
    <tr align="center">
    <td height="25"><span class="style1">单选区</span></td>
    <td class="style1"> 投票主题(<?php echo $lmlb;?>)</td>
    <td width="173" colspan="2" class="style1">投票结果</td>
    </tr>
   <?php
  $query="select * from tb_poll1 where tpzt='$lmlb'";
  $result=mysql_query($query);
  while($myrow=mysql_fetch_array($result)){
  ?>
  <tr>
    <td width="81" height="22" align="center"><span class="style2"><?php echo $myrow[tpnr];?></span></td>
    <td width="188" align="center">
                    <input name="ljid" type="radio" value="<?php echo $myrow[id];?>">
                <input type="hidden" name="tpzt1" value="<?php echo $myrow[tpzt];?>">   </td>
 <td height="22" colspan="2" align="center"><table width="150" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="115" align="center" class="style2"><?php echo $myrow[tpnr];?></td>
        <td width="179" class="style2"> <?php echo $myrow[tpcs];?></td>
      </tr>
    </table></td>
    </tr>
 <?php }?>
  <tr>
    <td height="25"> </td>
    <td colspan="3"> <input type="submit" name="Submit" value="提交"></td>
    </tr>
  </form>
</table> 
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="提交" onclick="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 * 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="739" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">

    <tr>

      <td colspan="3" class="font1 td1">题目:<?php echo $OJBName?></td>

    </tr>

    <tr>

      <td align="center" bgcolor="#FFFFFF" class="font2">选项</td>

      <td align="center" bgcolor="#FFFFFF" class="font2">比例</td>

      <td align="center" bgcolor="#FFFFFF" class="font2">票数</td>

    </tr>

<?php

//计算总票数

$Sql="select sum(`Num`) as VoteCount from tselect where ObjID='".$ObjID."'";

$Result=mysql_query($Sql);

$Arr=mysql_fetch_array($Result);

$VoteCount=$Arr['VoteCount'];

$Sql="select * from tselect where ObjID='".$ObjID."'";

$Result=mysql_query($Sql);

while($Arr=mysql_fetch_array($Result))

   {

   $Percent=round(($Arr['Num']/$VoteCount)*100,2);

   $Width=round($Percent*4,0);

?>

    <tr>

      <td width="214" bgcolor="#FFFFFF" class="font2"><?php echo $Arr['SName']?></td>

      <td width="405" bgcolor="#FFFFFF" class="font2"><img src="images/per.gif" width="<?php echo $Width?>" height="20" align="absmiddle" /> (<?php echo $Percent."%"?>)</td>

      <td width="98" align="center" bgcolor="#FFFFFF" class="font2"><?php echo $Arr['Num']?></td>

    </tr>

<?

   }

?>

</table>

<table width="739" border="0" align="center" cellpadding="0" cellspacing="0">

    <tr>

      <td width="739" height="41" align="center"><input type="button" name="Submit" value="返回" onclick="window.location.href='index.php'" />

      </td>

    </tr>

</table>

</form>

</body>

</html>

public.js

function selectAll(obj) {

for(var i = 0;i<obj.elements.length;i++)

if(obj.elements[i].type == "checkbox")

obj.elements[i].checked = true;

}

function selectOther(obj) {

for(var i = 0;i<obj.elements.length;i++)

if(obj.elements[i].type == "checkbox" ) {

   if(!obj.elements[i].checked)

    obj.elements[i].checked = true;

   else

    obj.elements[i].checked = false;

}

}

function objedit(page,f,id)

{

f.opt.value="edit";

f.ID.value=id;

f.action=page;

f.submit();

}

function Objadd(page,f)

{

f.opt.value="add";

f.action=page;

f.submit();

}

function objdel(page,f,id)

{

if(confirm("您确认要删除这个项目吗?"))

{

f.opt.value="del";

f.ID.value=id

f.action=page;

f.submit();

}

}

function Objdelsel(page,f)

{

if(confirm("您确认要删除这些项目吗?"))

{

f.opt.value="delsel";

f.action=page;

f.submit();

}

}

function objselect(page,f,id)

{

f.opt.value="list";

f.ObjID.value=id;

f.action=page;

f.submit();

}

function lookresult(page,f,opt)

{

f.opt.value=opt;

f.action=page;

f.submit();

}

conn.php

<?php

$Host="localhost";

$UserName="root";

$Password="111";

$DB="toupiao";

@mysql_connect($Host,$UserName,$Password) or die("连接数据库服务器失败,请与系统管理员联系");

@mysql_select_db($DB) or die("连接数据库失败,请与系统管理员联系");

?>

style.css

.font1{ font-family:"宋体"; font-size:12px; line-height:23px; font-weight:bold;}

.font2{ font-family:"宋体"; font-size:12px; line-height:23px;}

.font3{ font-family:"宋体"; font-size:12px;}

.td1{ border:1px solid #FFF;}

后台代码:

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>

<body>

<table width="862" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">

    <form id="form1" name="form1" method="post" action="">

<tr>

      <td width="20" align="center" class="font1 td1"> </td>

      <td width="68" align="center" class="font1 td1">编号</td>

      <td width="169" align="center" class="font1 td1">类别</td>

      <td width="409" align="center" class="font1 td1">

     <input name="opt" type="hidden" id="opt" />

        <input name="ID" type="hidden" id="ID" />

        <input name="ObjID" type="hidden" id="ObjID" />

        项目</td>

      <td width="160" align="center" class="font1 td1">操作</td>

    </tr>

<?php

$Sql="select * from tobject order by ID asc";

$Result=mysql_query($Sql);

while($Arr=@mysql_fetch_array($Result))

   {

?>

    <tr>

      <td bgcolor="#FFFFFF" class="font2"><input name="IDArr[]" type="checkbox" id="IDArr[]" value="<?php echo $Arr['ID']?>" /></td>

      <td align="center" bgcolor="#FFFFFF" class="font2"><?php echo $Arr['ID']?></td>

      <td align="center" bgcolor="#FFFFFF" class="font2"><?php echo ($Arr['SType']=="0")?"单选":"多选"?></td>

      <td align="left" bgcolor="#FFFFFF" class="font2"><?php echo $Arr['OJBName']?></td>

      <td align="center" bgcolor="#FFFFFF" class="font2">[<a href="javascript:objedit('objopt.php',document.form1,<?php echo $Arr['ID']?>)">编辑</a>][<a href="javascript:objdel('objopt.php',document.form1,<?php echo $Arr['ID']?>)">删除</a>][<a href="javascript:objselect('select.php',document.form1,<?php echo $Arr['ID']?>)">选项</a>]</td>

    </tr>

    <?

   }

?>

<tr>

      <td colspan="3" align="center" bgcolor="#FFFFFF" class="font2">[<a href="javascript:selectAll(document.form1);">全选</a>][<a href="javascript:selectOther(document.form1);">反选</a>][<a href="javascript:Objadd('objopt.php',document.form1);">增加</a>][<a href="javascript:Objdelsel('objopt.php',document.form1);">删除</a>]</td>

      <td colspan="2" align="center" bgcolor="#FFFFFF" class="font2"> </td>

      </tr>

</form>

</table>

</body>

</html>

objopt.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

$opt=$_POST['opt'];

$ID=$_POST['ID'];

$IDArr=$_POST['IDArr'];

switch ($opt)

{

case "add":

    $OptName="添加新项目";

$OptStr="int";

break;

case "int":

    $Sql="insert into tobject (OJBName,SType) values('".$_POST['OJBName']."','".$_POST['SType']."')";

if(@mysql_query($Sql))

   {

   echo "<script>alert('添加成功!');window.location.href='index.php';</script>";

   exit;

   }

else

   {

   echo "<script>alert('添加失败!');window.location.href='index.php';</script>";

   exit;

   }

break;

case "edit":

    $OptName="编辑项目";

$OptStr="upd";

$Sql="select * from tobject where ID='".$ID."'";

$Result=@mysql_query($Sql);

$Arr=@mysql_fetch_array($Result);

$OJBName=$Arr['OJBName'];

$SType=$Arr['SType'];

break;

case "upd":

    $Sql="update tobject set OJBName='".$_POST['OJBName']."',SType='".$_POST['SType']."' where ID='".$ID."'";

if(@mysql_query($Sql))

   {

   echo "<script>alert('编辑成功!');window.location.href='index.php';</script>";

   exit;

   }

else

   {

   echo "<script>alert('编辑失败!');window.location.href='index.php';</script>";

   exit;

   }

break;

case "del":

    $Sql="delete from tobject where ID='".$ID."'";

if(@mysql_query($Sql))

   {

   echo "<script>alert('删除成功!');window.location.href='index.php';</script>";

   exit;

   }

else

   {

   echo "<script>alert('删除失败!');window.location.href='index.php';</script>";

   exit;

   }

break;

case "delsel":

    $Count=count($IDArr);

if($Count>0)

   {

   $SqlStr="";

   for($i=0;$i<$Count;$i++)

     {

     $SqlStr.=" ID=".$IDArr[$i]." or ";

     }

   $SqlStr=substr($SqlStr,0,strlen($SqlStr)-4);

   $Sql="delete from tobject where ".$SqlStr;

   if(@mysql_query($Sql))

     {

     echo "<script>alert('删除成功!');window.location.href='index.php';</script>";

     exit;

     }

   else

     {

     echo "<script>alert('删除失败!');window.location.href='index.php';</script>";

     exit;

     }

   }

else

   {

   echo "<script>alert('提交参数错误,没有选择任何要删除的项目!');window.location.href='index.php';</script>";

   }

break;

}

?>

<body>

<form id="form1" name="form1" method="post" action="">

<table width="862" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">

    <tr>

      <td colspan="2" align="left" class="font1"> <?php echo $OptName?></td>

    </tr>

    <tr>

      <td width="242" align="right" bgcolor="#FFFFFF" class="font1">项目名称:</td>

      <td width="605" align="left" bgcolor="#FFFFFF" class="font2"><input name="OJBName" type="text" class="font3" id="OJBName" value="<?php echo $OJBName?>" size="70" /></td>

    </tr>

    <tr>

      <td align="right" bgcolor="#FFFFFF" class="font1">项目类型:</td>

      <td align="left" bgcolor="#FFFFFF" class="font2"><input name="SType" type="radio" value="0" <?php if($SType=="0" || trim($SType)=="") echo "checked";?> />

        单选

          <input type="radio" name="SType" value="1" <?php if($SType=="1") echo "checked";?> />

      多选

      <input name="opt" type="hidden" id="opt" value="<?php echo $OptStr?>" />

      <input name="ID" type="hidden" id="ID" value="<?php echo $ID?>" /></td>

    </tr>

</table>

<table width="862" border="0" align="center" cellpadding="0" cellspacing="0">

    <tr>

      <td height="38" align="center"><input type="submit" name="Submit" value="提交" />

        <label>



        <input type="reset" name="Submit2" value="重置" />

      </label></td>

    </tr>

</table>

</form>

</body>

</html>

select.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>

<body>

<table width="862" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">

    <form id="form1" name="form1" method="post" action="">

<tr>

      <td width="20" align="center" class="font1 td1"> </td>

      <td width="68" align="center" class="font1 td1">编号</td>

      <td width="169" align="center" class="font1 td1">投票数</td>

      <td width="409" align="center" class="font1 td1">

     <input name="opt" type="hidden" id="opt" />

        <input name="ID" type="hidden" id="ID" value="" />

        <input name="ObjID" type="hidden" id="ObjID" value="<?php echo $_REQUEST['ObjID']?>" />

        选项</td>

      <td width="160" align="center" class="font1 td1">操作</td>

    </tr>

<?php

$Sql="select * from tselect where ObjID='".$_REQUEST['ObjID']."' order by ID asc";

$Result=mysql_query($Sql);

while($Arr=@mysql_fetch_array($Result))

   {

?>

    <tr>

      <td bgcolor="#FFFFFF" class="font2"><input name="IDArr[]" type="checkbox" id="IDArr[]" value="<?php echo $Arr['ID']?>" /></td>

      <td align="center" bgcolor="#FFFFFF" class="font2"><?php echo $Arr['ID']?></td>

      <td align="center" bgcolor="#FFFFFF" class="font2"><?php echo $Arr['Num']?></td>

      <td align="left" bgcolor="#FFFFFF" class="font2"><?php echo $Arr['SName']?></td>

      <td align="center" bgcolor="#FFFFFF" class="font2">[<a href="javascript:objedit('selopt.php',document.form1,<?php echo $Arr['ID']?>)">编辑</a>][<a href="javascript:objdel('selopt.php',document.form1,<?php echo $Arr['ID']?>)">删除</a>]</td>

    </tr>

    <?

   }

?>

<tr>

      <td colspan="3" align="center" bgcolor="#FFFFFF" class="font2">[<a href="javascript:selectAll(document.form1);">全选</a>][<a href="javascript:selectOther(document.form1);">反选</a>][<a href="javascript:Objadd('selopt.php',document.form1);">增加</a>][<a href="javascript:Objdelsel('selopt.php',document.form1);">删除</a>][<a href="index.php">返回</a>]</td>

      <td colspan="2" align="center" bgcolor="#FFFFFF" class="font2"> </td>

      </tr>

</form>

</table>

</body>

</html>

selopt.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

$opt=$_POST['opt'];

$ID=$_POST['ID'];

$IDArr=$_POST['IDArr'];

switch ($opt)

{

case "add":

    $OptName="添加新选项";

$OptStr="int";

break;

case "int":

    $Sql="insert into tselect (ObjID,SName,`Num`) values('".$_POST['ObjID']."','".$_POST['SName']."','0')";

if(@mysql_query($Sql))

   {

   echo "<script>alert('添加成功!');window.location.href='select.php?ObjID=".$_POST['ObjID']."';</script>";

   exit;

   }

else

   {

   echo "<script>alert('添加失败!');window.location.href='select.php?ObjID=".$_POST['ObjID']."';</script>";

   exit;

   }

break;

case "edit":

    $OptName="编辑选项";

$OptStr="upd";

$Sql="select * from tselect where ID='".$ID."'";

$Result=@mysql_query($Sql);

$Arr=@mysql_fetch_array($Result);

$SName=$Arr['SName'];

break;

case "upd":

    $Sql="update tselect set ObjID='".$_POST['ObjID']."',SName='".$_POST['SName']."' where ID='".$ID."'";

if(@mysql_query($Sql))

   {

   echo "<script>alert('编辑成功!');window.location.href='select.php?ObjID=".$_POST['ObjID']."';</script>";

   exit;

   }

else

   {

   echo "<script>alert('编辑失败!');window.location.href='select.php?ObjID=".$_POST['ObjID']."';</script>";

   exit;

   }

break;

case "del":

    $Sql="delete from tselect where ID='".$ID."'";

if(@mysql_query($Sql))

   {

   echo "<script>alert('删除成功!');window.location.href='select.php?ObjID=".$_POST['ObjID']."';</script>";

   exit;

   }

else

   {

   echo "<script>alert('删除失败!');window.location.href='select.php?ObjID=".$_POST['ObjID']."';</script>";

   exit;

   }

break;

case "delsel":

    $Count=count($IDArr);

if($Count>0)

   {

   $SqlStr="";

   for($i=0;$i<$Count;$i++)

     {

     $SqlStr.=" ID=".$IDArr[$i]." or ";

     }

   $SqlStr=substr($SqlStr,0,strlen($SqlStr)-4);

   $Sql="delete from tselect where ".$SqlStr;

   if(@mysql_query($Sql))

     {

     echo "<script>alert('删除成功!');window.location.href='select.php?ObjID=".$_POST['ObjID']."';</script>";

     exit;

     }

   else

     {

     echo "<script>alert('删除失败!');window.location.href='select.php?ObjID=".$_POST['ObjID']."';</script>";

     exit;

     }

   }

else

   {

   echo "<script>alert('提交参数错误,没有选择任何要删除的选项!');window.location.href='select.php?ObjID=".$_POST['ObjID']."';</script>";

   }

break;

}

?>

<body>

<form id="form1" name="form1" method="post" action="">

<table width="862" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">

    <tr>

      <td colspan="2" align="left" class="font1"> <?php echo $OptName?>

      <input name="ID" type="hidden" id="ID" value="<?php echo $_POST['ID'];?>" />

      <input name="ObjID" type="hidden" id="ObjID" value="<?php echo $_POST['ObjID']?>" />

      <input name="opt" type="hidden" id="opt" value="<?php echo $OptStr?>" /></td>

    </tr>

    <tr>

      <td width="242" align="right" bgcolor="#FFFFFF" class="font1">项目名称:</td>

      <td width="605" align="left" bgcolor="#FFFFFF" class="font2"><input name="SName" type="text" class="font3" id="SName" value="<?php echo $SName?>" size="70" /></td>

    </tr>

</table>

<table width="862" border="0" align="center" cellpadding="0" cellspacing="0">

    <tr>

      <td height="38" align="center"><input type="submit" name="Submit" value="提交" />

        <label>



        <input type="reset" name="Submit2" value="重置" />

      </label></td>

    </tr>

</table>

</form>

</body>

</html>

数据库表结构:

--

-- 表的结构 `iptable`

--

CREATE TABLE `iptable` (

`ID` int(11) NOT NULL auto_increment,

`ObjID` int(11) NOT NULL,

`IP` varchar(50) default '0.0.0.0',

PRIMARY KEY (`ID`)

)

--

-- 表的结构 `tobject`

--

CREATE TABLE `tobject` (

`ID` int(11) NOT NULL auto_increment,

`OJBName` varchar(255) character set utf8 default NULL,

`SType` int(1) NOT NULL default '0',

PRIMARY KEY (`ID`)

)

--

-- 表的结构 `tselect`

--

CREATE TABLE `tselect` (

`ID` int(11) NOT NULL auto_increment,

`ObjID` int(11) default '0',

`SName` varchar(255) default NULL,

`Num` bigint(25) default '0',

PRIMARY KEY (`ID`)

)
01-08 11:16