怎么在PHP中使用MySQL编写一个投票系统

发布时间:2021-01-22 15:30:23 作者:Leah
来源:亿速云 阅读:130

这篇文章给大家介绍怎么在PHP中使用MySQL编写一个投票系统,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

具体如下:

<html>
<head><title>手机系统调查问卷</title>
<style type="text/css">
<!--
span{
  width:600px;
  height:100px;
  background-color:write;
  postion:relative;
  border:1px #cccccc solid;
}
div{
  width:60px;
  height:1px;
  background-color:blue;
  postion:absolute;
  bottom:0;
}
-->
</style>
</head>
<body>
你现在使用的手机是什么系统?
<form id="form1" method="POST" action="count.php">
<input type="radio" name="phone" value="1"> Android安卓
<input type="radio" name="phone" value="2"> Symbian塞班
<br>
<input type="radio" name="phone" value="3"> iphone苹果
<input type="radio" name="phone" value="4"> Google谷歌
<br>
<input type="radio" name="phone" value="5"> Winphone微软
<input type="radio" name="phone" value="6"> 其它
<br>
<input type="submit" value="提交">
</form>
<span>
当前票数:<br>
<?php
include 'connect.php';
$sql="select answer from countone";
$rs=mysql_query($sql);
$total=mysql_num_rows($rs);
$sql="select * from countone where answer=1";
$rs=mysql_query($sql);
$android=mysql_num_rows($rs);
$sql="select * from countone where answer=2";
$rs=mysql_query($sql);
$symbian=mysql_num_rows($rs);
$sql="select * from countone where answer=3";
$rs=mysql_query($sql);
$iphone=mysql_num_rows($rs);
$sql="select * from countone where answer=4";
$rs=mysql_query($sql);
$google=mysql_num_rows($rs);
$sql="select * from countone where answer=5";
$rs=mysql_query($sql);
$winphone=mysql_num_rows($rs);
$sql="select * from countone where answer=6";
$rs=mysql_query($sql);
$other=mysql_num_rows($rs);
?>
<table border="0">
<th>android</th><th>Symbian</th><th>iphone</th><th>Google</th><th>winphone</th><th>other</th>
<tr>
<td><?php echo $android ?>票</td>
<td><?php echo $symbian ?>票</td>
<td><?php echo $iphone ?>票</td>
<td><?php echo $google ?>票</td>
<td><?php echo $winphone ?>票</td>
<td><?php echo $other ?>票</td>
</tr>
<tr>
<td><?php for ($i=1;$i<=$android/$total+1;$i=$i+0.1){  echo "<div></div>"; } ?></td>
<td><?php for ($i=1;$i<=$symbian/$total+1;$i=$i+0.1){  echo "<div></div>"; } ?></td>
<td><?php for ($i=1;$i<=$iphone/$total+1;$i=$i+0.1){  echo "<div></div>"; } ?></td>
<td><?php for ($i=1;$i<=$google/$total+1;$i=$i+0.1){  echo "<div></div>"; } ?></td>
<td><?php for ($i=1;$i<=$winphone/$total+1;$i=$i+0.1){ echo "<div></div>"; } ?></td>
<td><?php for ($i=1;$i<=$other/$total+1;$i=$i+0.1){ echo "<div></div>"; } ?></td>
</tr>
</table>
</span>
</body>
</html>

写的有点啰嗦,有点笨但很实用

<?php
include 'connect.php';
$name=$_POST['phone'];
$sql="insert into countone values(null,$name,now(),null)";
mysql_query($sql);
?>
<script type="text/javascript">
 alert ("投票成功!");
 location="question.php";
</script>

链接mysql:

<?php
mysql_connect("localhost","root","");
mysql_select_db("vote");
mysql_query("set names utf8");
?>

关于怎么在PHP中使用MySQL编写一个投票系统就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. js脚本如何编写刷票投票系统
  2. 如何使用php做出简易在线投票系统

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php mysql

上一篇:利用PHP怎么根据时间戳获取星期几

下一篇:PHP中实现异步调用的方法有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》