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
<center><input type="submit" name="send" value="发布"><li>注意:一旦发布将不能修改!</li></center>
<?php //发布 if(@$_POST['send']){ $ouser=@$_GET['user']; if($ouser != ''){ $vname=@$_POST[voteName]; $time=time(); $starttime=date("y-m-d",$time); $vintro=@$_POST[voteIntro]; $open=@$_POST[voteOpen]; $more=@$_POST[voteSel]; $max=@$_POST[itemMax]; $min=@$_POST[itemMin]; $itemcount=@$_POST[voteCount]; //为了方便最后完成字符串,让$item先等于$_POST[1],这样在下面的for循环中要少循环一次 $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'; } $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 "<script language='javascript'> alert('成功提交!'); </script>"; } else{ echo "<script language='javascript'> alert('选项设置有误!'); </script>"; } }else{ echo "<script language='javascript'> alert('请先登录!'); </script>"; } } ?>
$ouser=@$_GET['user']; if($ouser != ''){
$time=time(); $starttime=date("y-m-d",$time);
$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'; }
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.