Simple online voting system php - publish voting page

WBOY
Release: 2016-07-29 09:07:02
Original
2228 people have browsed it

Publishing the page can only be done when the user is logged in, so you need to check whether you are logged in first, and then allow voting to be posted after confirmation

  • 注意:一旦发布将不能修改!
  • Copy after login

    The information entered by the user will be published to the background in post format.

    =$min && $vname!=""){ for($i=1;$i<$itemcount;$i++){ $j=$i+1; $item=$item.'*'.@$_POST[$j]; $num=$num.'*0'; } $sql3="SELECT uid FROM users WHERE username='$ouser'"; $getVid=mysql_query($sql3); $row=mysql_fetch_row($getVid); $uid=$row[0]; $sql="insert into vote(vname,starttime,uid,vintro,open,more,max,min) value('$vname','$starttime','$uid','$vintro','$open','$more','$max','$min')"; mysql_query($sql); $sql2="SELECT vid FROM vote WHERE vname='$vname'"; $getVid=mysql_query($sql2); $row=mysql_fetch_row($getVid); $vid=$row[0]; $sql4="insert into votetitle(vid,itemcount,item,num) value('$vid','$itemcount','$item','$num')"; mysql_query($sql4); echo ""; } else{ echo ""; } }else{ echo ""; } } ?>
    Copy after login

    1. Check whether you are logged in

    $ouser=@$_GET['user']; if($ouser != ''){
    Copy after login
    2. Get the current time
    $time=time(); $starttime=date("y-m-d",$time);
    Copy after login
    3. Form option information and voting statistical information that can be saved in the database

    $item=@$_POST[1]; $num=0; if($max>=$min && $vname!=""){ for($i=1;$i<$itemcount;$i++){ $j=$i+1; $item=$item.'*'.@$_POST[$j]; $num=$num.'*0'; }
    Copy after login
    (1) Option information and voting statistical information are both obtained by combining the option information Use "*" to separate them to form a string

    Example: "Option 1*Option 2*Option 3"

    (2) Default initial voting statistics, all items are 0.

    Example: "0*0*0"

    (3) This loop statement is actually unnecessary. PHP provides special methods to integrate and decompose arrays into strings (explode and implode), but in When I completed this part of the code, I didn't know the application of this method, so I completed this function myself.

    The above introduces the simple online voting system PHP - publishing the voting page, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!