PHP ajax mysql投票按钮,不注册先点击
php ajax mysql voting button, doesn't register first click
我有一个简单的(或我认为)PHP, MYSQL, AXAX系统设置注册投票项目在我的网站。我只做了upVotes,所以只有一个按钮。
我的问题是,当页面加载时,显示该项目的正确投票数,但在第一次单击upVote按钮时,值没有改变。我知道我一定错过了什么,但我不知道是什么。这可能很简单……但我就是想不明白。
一切连接到DB都很好。所以我才没写代码。
感谢您的帮助。
这是我的javascript:
<script type="text/javascript">
function voteButton(str)
{
if (str=="")
{
document.getElementById("voteUp").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("voteUp").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","vote?id="+str,true);
xmlhttp.send();
}
</script>
这是用来查询数据库的php文件:
<?php
$id=$_GET["id"];
include("myDatabaseStuff.php");
include("global.php");
$result = mysql_query("UPDATE TABLE SET up_mod = up_mod + 1 WHERE img_id = $id");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
while($row = mysql_fetch_array($getUpVoteResult))
{
echo $row['up_mod'];
}
?>
这是我在页面上用来显示values/按钮的HTML:
<div class="span1" style="margin:30px 0 0 10px;">
<button onclick="voteButton('<?php echo $id;?>')" class="btn btn-large" type="button" style="margin-top:5px"><div id="voteUp"><?php echo $votes[0] ?></div><i class="icon-thumbs-up"></i></button>
</div>
添加:
$getUpVoteResult = mysql_query("SELECT up_mod FROM table WHERE img_id = $id") or die ("Invalid query: " . mysql_error());
在while
环前。
也不需要while循环,因为只有一行。
更新后,请单独执行SELECT
。
相关文章:
- 如何在单击“提交”按钮时为“新建”窗口编写JavaScript,用“确定”和“取消”显示注册信息
- 单击按钮时切换html登录/注册表单
- 设置重复按钮以注册点击事件jquery
- 我需要一个注册按钮,它可以将数据发送到mySQL服务器,也可以在单击时重定向
- 我需要在同一页面上同时使用“使用谷歌登录”和“使用谷歌注册”按钮
- 通过单击按钮或表单提交禁用注册按钮,这两种方式都会阻止表单提交
- JQuery 按钮单击未注册
- 如何在警报框关闭后将按钮的文本更改为“禁止注册!
- 单击注册具有相同类名的多个按钮
- 两个登录/注册按钮是相同的.如何为同一个按钮提供 2 个功能
- 如果未选中复选框,如何禁用注册按钮
- 点击注册按钮生成一个随机数
- Javascript/PHP事件更新注册按钮
- 如何在所有字段为true后激活注册按钮
- Slack频道注册按钮不显示加载ajax页面内容时
- 如何使注册按钮只有在密码强度好或强时才启用
- 注册按钮不工作在我的Launchrock小部件
- JQuery未注册按钮点击
- 我想检索活动,来源和媒体我的网站上的注册按钮点击
- 如何在谷歌分析中点击注册按钮