µ±Ç°Î»ÖãºÊ×Ò³ > ¿ª·¢½Ì³Ì > php½Ì³Ì >

PHPʵս֮ͶƱϵͳµÄʵÏÖ

ʱ¼ä£º2022-04-16 12:31 À´Ô´£ºÎ´Öª ×÷ÕߣºÓµÕß²»Õä ÊÕ²Ø

ÕâÆªÎÄÕÂÖ÷ҪΪ´ó¼Ò½éÉÜÁËÈçºÎÀûÓÃPHPÖÆ×÷Ò»¸öͶƱϵͳ£¬ÎÄÖеÄʾÀý´úÂë½²½âÏêϸ£¬¸ÐÐËȤµÄС»ï°é¿ì¸úËæÐ¡±àÒ»ÆðѧϰһÏÂ

Ò»¡¢ÊµÏÖ´úÂë

1.sql

-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: 2022-03-28 05:42:05
-- ·þÎñÆ÷°æ±¾£º10.1.13-MariaDB
-- PHP Version: 5.6.21

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `a`
--

-- --------------------------------------------------------

--
-- ±íµÄ½á¹¹ `voto`
--

CREATE TABLE `voto` (
  `id` int(10) NOT NULL,
  `titleid` int(10) DEFAULT NULL,
  `item` varchar(50) DEFAULT NULL,
  `count` int(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- ת´æ±íÖеÄÊý¾Ý `voto`
--

INSERT INTO `voto` (`id`, `titleid`, `item`, `count`) VALUES
(24, 1, 'ÕÅѧÓÑ', 0),
(25, 1, '³ÂÞÈѸ', 0),
(26, 1, 'ÁÖ¿¡½Ü', 0),
(27, 1, 'Ïô¾´ÌÚ', 0),
(29, 1, '', 0),
(30, 1, 'aaa', 0);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `voto`
--
ALTER TABLE `voto`
  ADD PRIMARY KEY (`id`);

--
-- ÔÚµ¼³öµÄ±íʹÓÃAUTO_INCREMENT
--

--
-- ʹÓñíAUTO_INCREMENT `voto`
--
ALTER TABLE `voto`
  MODIFY `id` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

2.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <a href="admin.php" rel="external nofollow" >Ôöɾ¸Ä²éͶƱµÄÑ¡Ïî</a>
<br>
  <a href="index.php" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >ͶƱ¸øË­ÄØ</a>
</body>
</html>

3.admin.php£¨Ôöɾ¸Ä²éͶƱµÄÒ³Ãæ£©ÃÜÂ룺admi

<php
ob_start(); //´ò¿ª»º³åÇø 
session_start();
header("Content-type:text/html;charset=utf-8");

$link = mysqli_connect('localhost','root','','a');
mysqli_set_charset($link, "utf8");
if (!$link) {
  die("Á¬½Óʧ°Ü:".mysqli_connect_error());
}
>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>PHP+mysql¿ª·¢µÄ¼òµ¥Í¶Æ±ÏµÍ³</title>
  <style type="text/css">
    /*È«¾ÖÑùʽ*/
    body { font-family: "ËÎÌå"; font-size: 12pt; color: #333333; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;background-color: #d4d4d4;}
    table { font-family: "ËÎÌå"; font-size: 9pt; line-height: 20px; color: #333333}
    /*È«¾ÖÑùʽ½áÊø*/
</style>
  <script language="javascript">
    function selectAll()
{
      node=window.document.frm.itm;
      for(i=0;i<node.length;i++)
      {
        node[i].checked=true;//ȫѡ
      }
    }
    function cancelAll()
{
      node=frm.itm;
      for(i=0;i<node.length;i++)
      {
        node[i].checked=false;//È¡ÏûÈ«²¿
      }
    }
    function del()
{
      node=frm.itm;
      id="";
      for(i=0;i<node.length;i++)
      {
        if(node[i].checked)
        {
          if(id=="")//ɾ³ý
          {
            id=node[i].value
          }
          else
          {
            id=id+","+node[i].value
          }
        }
      }
      if(id=="")
      {
        alert("ÄúûÓÐÑ¡Ôñɾ³ýÏî");
      }
      else
      {
        location.href="type=del&id=" rel="external nofollow" +id
      }
    }
</script>
</head>
<body>

<php
if(isset($_GET['tj']) == 'out'){
  session_destroy();//ɾ³ýµ±Ç°Óû§¶ÔÓ¦µÄsessionÎļþÒÔ¼°ÊÍ·Åsession
  echo "<script language=javascript>alert('Í˳ö³É¹¦£¡');window.location='index.php'</script>";
}
>

<php
if(isset($_POST['Submit10'])){
  if($_POST['pwd']=='admin'){

    $_SESSION['pwd']=2;

    echo "<script language=javascript>alert('µÇ½³É¹¦£¡');window.location='admin.php'</script>";
  }else{
    echo "<script language=javascript>alert('µÇ½ʧ°Ü,Çë¼ì²éÄúµÄÃÜÂ룡');window.location='admin.php'</script>";
  }
}
>

<php if($_SESSION['pwd']<>2){ >
  <form action="" method="post">
    <table width="365" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#C2C2C2">
      <tr>
        <td height="30" align="right" bgcolor="#FFFFFF"><label>ÊäÈëÃÜÂ룺</label></td>
        <td align="left" bgcolor="#FFFFFF"><input name="pwd" type="text" id="pwd" /></td>
      </tr>
      <tr>
        <td height="30" colspan="2" align="center" bgcolor="#FFFFFF"><label>
            <input name="Submit10" type="submit" id="Submit10" value="怫" />
          </label>
          <label>  
            <input type="reset" name="Submit5" value="ÖØÖÃ" />
          </label></td>
      </tr>
      <tr>
        <td height="30" colspan="2" align="center" bgcolor="#FFFFFF">
          Èí¼þ°æ±¾£º<script type="text/javascript" src="http://www.04ie.com/net/phpvoto1_1.js"></script></td>
      </tr>
    </table>
  </form>
<php }else{ >
<php
if(isset($_POST["Submit"]))
{
$title=$_POST["title"];
$sql="update vototitle set vototitle='$title'";
mysqli_query($link,$sql);
>
  <script language="javascript">
    alert("Ð޸ijɹ¦");
</script>
<php
}
if(isset($_POST["Submit2"]))
{
  $newitem=$_POST["newitem"];
  $sql="insert into voto (titleid,item,count) values (1,'$newitem',1)";
  mysqli_query($link,$sql);

}
>
  <form id="frm" name="frm" method="post" action="" style="margin-bottom:3px;">
    <table width="365" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#C2C2C2">
      <tr>
        <td colspan="4" bgcolor="#FFFFFF"><label>
            <php
            $sql="select * from vototitle";
            $rs=mysqli_query($link,$sql);
            $rows=mysqli_fetch_assoc($rs);
            >
            <input name="title" type="text" id="title" size="35" value="<php echo $rows["vototitle"]>" />
          </label></td>
        <td width="68" align="center" bgcolor="#FFFFFF"><label>
            <input type="submit" name="Submit" value="Ð޸ıêÌâ" />
          </label></td>
      </tr>
      <tr>
        <th width="30" bgcolor="#FFFFFF">񅧏</th>
        <th width="45" bgcolor="#FFFFFF">ÏîÄ¿</th>
        <th width="52" bgcolor="#FFFFFF">ƱÊý</th>
        <th width="50" align="center" bgcolor="#FFFFFF">ÐÞ¸Ä</th>
        <th align="center" bgcolor="#FFFFFF">ɾ³ý</th>
      </tr>
      <php
      $sql="select * from voto order by count desc";
      $rs=mysqli_query($link,$sql);
      while($rows=mysqli_fetch_assoc($rs))
      {
        >
        <tr>
          <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="itm" value="<php echo $rows["id"]>" /><php echo $rows["id"]></td>
          <td align="center" bgcolor="#FFFFFF"><php echo $rows["item"]></td>
          <td align="center" bgcolor="#FFFFFF"><php echo $rows["count"]></td>
          <td align="center" bgcolor="#FFFFFF"><input type="button" value="ÐÞ¸Ä" onclick="location.href='type=modify&id=<php echo $rows["id"]>'" /></td>
          <td align="center" bgcolor="#FFFFFF"><input type="button" value="ɾ³ý" onclick="location.href='type=del&id=<php echo $rows["id"]>'"  /></td>
        </tr>
        <php
      }
      >
      <tr>
        <td colspan="5" align="center" bgcolor="#FFFFFF">
          <input type="button" value="Ñ¡ÔñÈ«²¿" onclick="selectAll()" />
          <input type="button" value="È¡ÏûÈ«²¿" onclick="cancelAll()" />
          <input type="button" value="ɾ³ýËùÑ¡" onclick="del()" />   </td>
      </tr>
      <tr>
        <td colspan="3" bgcolor="#FFFFFF"><label>
            <input name="newitem" type="text" id="newitem" />
          </label></td>
        <td colspan="2" bgcolor="#FFFFFF"><label>
            <input type="submit" name="Submit2" value="Ìí¼ÓÐÂÏî" />
              </label>
          <a href="tj=out" rel="external nofollow" >Í˳ö¹ÜÀí</a></td>
      </tr>
    </table>
  </form>

<php
$type = isset($_GET["type"])$_GET["type"]:"";
if($type =="modify"){

$id=$_GET["id"];
if(isset($_POST["Submit3"]))
{
  $item=$_POST["itm"];
  $count=$_POST["count"];
  $sql="update voto set item='$item',count=$count where id=$id";
  mysqli_query($link,$sql);
  echo "<script language=javascript>alert('Ð޸ijɹ¦£¡');window.location='admin.php'</script>";
}
$sql="select * from voto where id=$id";
$rs=mysqli_query($link,$sql);
$rows=mysqli_fetch_assoc($rs);
>
  <form id="form1" name="form1" method="post" action="" style="margin-top:2px;">
    <table width="365" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#C2C2C2">
      <tr>
        <th colspan="2" bgcolor="#FFFFFF">ÐÞ¸ÄͶƱÏîÄ¿</th>
      </tr>
      <tr>
        <td align="center" bgcolor="#FFFFFF">Ãû³Æ:</td>
        <td bgcolor="#FFFFFF"><label>
            <input name="itm" type="text" id="itm" value="<php echo $rows["item"]>" />
          </label></td>
      </tr>
      <tr>
        <td align="center" bgcolor="#FFFFFF">ƱÊý£º</td>
        <td bgcolor="#FFFFFF"><label>
            <input name="count" type="text" id="count" value="<php echo $rows["count"]>" />
          </label></td>
      </tr>
      <tr>
        <td colspan="2" align="center" bgcolor="#FFFFFF"><label>
            <input type="submit" name="Submit3" value="ÐÞ¸Ä" />
            <input type="reset" name="Submit" value="ÖØÖÃ" />
          </label></td>
      </tr>
    </table>
  </form>

  <php
}
  >
  <php
  $type = isset($_GET["type"])$_GET["type"]:"";
  if($type =="del"){
    $id=$_GET["id"];
    $sql="delete from voto where id in ($id)";
    mysqli_query($link,$sql);
    echo "<script language=javascript>alert('ɾ³ý³É¹¦£¡');window.location='admin.php'</script>";
  }
  >
<php } >
</body>
</html>

4.index.phpͶƱµÄÒ³Ãæ

<php
ob_start();
session_start();
header("Content-type:text/html;charset=utf-8");

$link = mysqli_connect('localhost','root','','a');
mysqli_set_charset($link, "utf8");
if (!$link) {
  die("Á¬½Óʧ°Ü:".mysqli_connect_error());
}

>
<!doctype html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>ͶƱϵͳ</title>
  <script type="text/javascript" src="//cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
  <style type="text/css">
    /*È«¾ÖÑùʽ*/
    body { font-family: "ËÎÌå"; font-size: 12pt; color: #333333; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;background-color: #A6C7E1;}
    table { font-family: "ËÎÌå"; font-size: 9pt; line-height: 20px; color: #333333}
    a:link { font-size: 9pt; color: #333333; text-decoration: none}
    a:visited { font-size: 9pt; color: #333333; text-decoration: none}
    a:hover { font-size: 9pt; color: #E7005C; text-decoration: underline}
    a:active { font-size: 9pt; color: #333333; text-decoration: none}
    /*È«¾ÖÑùʽ½áÊø*/
</style>
  <script language="javascript">
    function check()
{
      node=frm.itm;
      flag=false;
      for(i=0;i<node.length;i++)
      {
        if(node[i].checked)
        {
          flag=true;
        }
      }
      if(!flag)
      {
        alert("ÄúûÓÐÑ¡Ôñ")
        return false;
      }
      return true;
    }
</script>

  <php

  if(isset($_POST["submit"])){

    if($_POST){
      $id = $_POST["selected_id"];
      $sql = "update voto set count = count+1 where id=$id";
      mysqli_query($link,$sql);

    }

    if($_SESSION["voto"]==session_id())
    {
      >
      <script language="javascript">
        alert("ÄúÒѾ­Í¶Æ±ÁË");
        location.href="index.php" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ;
</script>
    <php
    exit();
    }
    $id=$_POST["itm"];
    $sql="update voto set count=count+1 where id=$id";
    if(mysqli_query($link,$sql))
    {
    $_SESSION["voto"]=session_id();
    >
      <script language="javascript">alert("ͶƱ³É¹¦,µãÈ·¶¨²é¿´½á¹û");location.href="index.phpid=ck" rel="external nofollow" ;</script>
    <php
    }
    else
    {
    >
      <script language="javascript">alert("ͶƱʧ°Ü");location.href="index.php" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" ;</script>
      <php
    }
  }
  >

</head>
<body>
<form name="frm" action="" method="post" onsubmit=return(check()) style="margin-bottom:5px;">
  <table width="365" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#C2C2C2">
    <tr>
      <th bgcolor="#FFFFCC">
        <php
        $sql="select * from vototitle";
        $rs=mysqli_query($link,$sql);
        $row=mysqli_fetch_assoc($rs);
        echo $row["vototitle"];
        > </th>
    </tr>
    <php
    $sql="select * from voto";
    $rs=mysqli_query($link,$sql);
    while($rows=mysqli_fetch_assoc($rs))
    {
      >
      <tr>
        <td bgcolor="#FFFFFF"><input type="radio" name="itm" value="<php echo $rows["id"]>" />  
          <php echo $rows["item"]></td>
      </tr>
      <php
    }
    >
    <tr>
      <td align="center" bgcolor="#FFFFFF">
        <input type="submit" name="submit" value="ͶƱ"/>
        <input type="hidden" id="selected_id" name="selected_id" value="">
        <input type="button" value="²é¿´½á¹û" onClick="location.href='index.phpid=ck'"/>  
        <script type="text/javascript">
            $("[type='radio']").click(function(){
               $("#selected_id").val($(this).val());
            });
</script></td>
    </tr>
  </table>
</form>
<php

if(isset($_GET["id"])=="ck"){>
  <php

  $sql="select sum(count) as 'total' from voto";
  $rs=mysqli_query($link,$sql);
  $rows=mysqli_fetch_assoc($rs);
  $sum=$rows["total"];  //µÃ³ö×ÜÆ±Êý

  $sql="select * from voto";
  $rs=mysqli_query($link,$sql);
  >
  <table id="click" width="365" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#C2C2C2" >
    <tr>
      <th bgcolor="#FFFFFF">ÏîÄ¿</th>
      <th bgcolor="#FFFFFF">ƱÊý</th>
      <th bgcolor="#FFFFFF">°Ù·Ö±È</th>
    </tr>
    <php
    while($rows=mysqli_fetch_assoc($rs))
    {
      >
      <tr>
        <td bgcolor="#FFFFFF"><php echo $rows["item"]></td>
        <td bgcolor="#FFFFFF"><php echo $rows["count"]></td>
        <td bgcolor="#FFFFFF">
          <php
          $per=$rows["count"]/$sum;
          $per=number_format($per,4);
          >
          <img src="" height="4" width="<php echo $per*100>" />
          <php echo $per*100>%      </td>
      </tr>
      <php
    }
    >
  </table>
  <div align="center">
    <a href="index.php" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow" >Òþ²Ø½á¹û</a>
  </div>
<php } >
</body>
</html>

¶þ¡¢Ð§¹ûͼ

PHPʵս֮ͶƱϵͳµÄʵÏÖ

PHPʵս֮ͶƱϵͳµÄʵÏÖ

µ½´ËÕâÆª¹ØÓÚPHPʵս֮ͶƱϵͳµÄʵÏÖµÄÎÄÕ¾ͽéÉܵ½ÕâÁË,¸ü¶àÏà¹ØPHPͶƱϵͳÄÚÈÝÇëËÑË÷Ô´ÂëËѲØÍøÒÔǰµÄÎÄÕ»ò¼ÌÐøä¯ÀÀÏÂÃæµÄÏà¹ØÎÄÕÂÏ£Íû´ó¼ÒÒÔºó¶à¶àÖ§³ÖÔ´ÂëËѲØÍø£¡


ÏÂһƪ£ºÃ»ÓÐÁË

php½Ì³ÌÔĶÁÅÅÐÐ

×îÐÂÎÄÕÂ