As shown in the picture, we choose to click the radio button in front of 123, and click "Vote" to add one vote to the number of votes for this project.
Create <input> radio button button and assign the name attribute
<input type="radio" name="itm" value="<?php echo $rows["id"]?>" />
Use SQL to operate the database to display all voting items in a loop.
<?php $SQL="SELECT * FROM vote"; $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 } ?>
When you click the "vote" button
<input type="submit" name="submit" value="投票"/>
The session operation is used here. When you have voted, the information will be stored In the session, it shows that you have already voted and cannot vote again.
If you have not voted, after you choose to vote, one vote will be automatically added to the number of votes for the selected project, and then the number of votes in the database will also be automatically added.
<?php if(isset($_POST["submit"])){ if($_SESSION["vote"]==session_id()) { ?> <script language="javascript"> alert("您已经投票了"); location.href="index.php"; </script> <?php exit(); } $id=$_POST["itm"]; $sql="update vote set count=count+1 where id=$id"; } ?>