PHP Voting system

Source: Internet
Author: User
Tags get ip

Poll categories

<! DOCTYPE html>PHP$db=NewMysqli ("localhost", "root", "root", "db_0808");$sql= "SELECT * FROM Fenlei";$result=$db->query ($sql);$data _c=$result-Fetch_all ();? ><table border= "1" > <?PHPforeach($data _c  as $i){    Echo"<tr><th><a href= ' vote.php?id={$i[0]} &is_radio={$i[2]} ' >{$i[1]} </a></th></tr> "; }?></table></body>

Voting interface

<! DOCTYPE html>PHP$id=$_get[' ID '];$is _radio=$_get[' Is_radio '];$db=NewMysqli ("localhost", "root", "root", "db_0808");$sql= "SELECT * from Toupiao WHERE category_id= ' {$id}‘";$result=$db->query ($sql);$data=$result-Fetch_all ();><form action= "tongji.php" method= "POST" ><table> <tr> <td> name </td> <t D> votes </td> </tr> <?PHPif($is _radio==1){    foreach($data  as $i){        Echo"<tr> <td>{$i[1]}</td> <td><input type= ' Radio ' name= ' r ' value= ' {$i[0]} ' ></td> </tr>"; }    }Else{        foreach($data  as $i){            Echo"<tr> <td>{$i[1]}</td> <td><input type= ' checkbox ' name= ' r[] ' value= ' {$i[0]} ' ></td> </tr>"; }    }    ?></table> <input type= "Submit" value= "Submission" ></form></body>

Voting processing

<! DOCTYPE html>PHP//$db = new mysqli ("localhost", "root", "root", "db_0808");require_once".. /zy/yin.class.php ";$db=NewYIN ();$ip=$_server[' REMOTE_ADDR '];//Get IP$sql= "SELECT count (*) from table2 where ip= ' {$ip}‘";$data=$db->strquery ($sql);if($data! = ' 0 '){    Echo"Everyone can only vote once a day.";$r=$_post[' R ']; if(Is_array($r)){            $s=implode(‘,‘,$r); $sq= "SELECT * from Toupiao where ID in ({$s})"; }Else{            $sq= "SELECT * from Toupiao where id = {$r}"; }        $qurle=$db->query ($sq); foreach($qurle  as $i){            Echo"<tr><td>{$i[1]} </td><td>{$i[2]} </td></tr> "; }}Else{    $sql= "INSERT into table2 VALUES (null, ' {$ip} ', DEFAULT) '; $squel=$db->strquery ($sql, 0); if($squel){//$upsql =update table_name Set votes = votes + 1 where ...//then insert the data into the Table2$r=$_post[' R '];if(Is_array($r)){    $s=implode(‘,‘,$r); $sql= "Update Toupiao set count= (count+1) where ID in ({$s})";}Else{$sql= "Update Toupiao set count= (count+1) where id = {$r}";}$data=$db->query ($sql, 0);if($data){//echo "Success";    if(Is_array($r)){        $s=implode(‘,‘,$r); $sq= "SELECT * from Toupiao where ID in ({$s})"; }Else{        $sq= "SELECT * from Toupiao where id = {$r}";} $qurle=$db->query ($sq); foreach($qurle  as $i){        Echo"<tr><td>{$i[1]} </td><td>{$i[2]} </td></tr> "; }}    }}?></table></body>

PHP Voting system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.