无需重新加载页面更新从MySQL表中的值? [英] Update values from MYSQL table without reloading the page?

查看:129
本文介绍了无需重新加载页面更新从MySQL表中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个家庭项目较小登录系统,这样,当用户执行登录,他是重定向到 userspage.php 。在页面我从我的MySQL表中的一些数据,但问题是,我的抓取显示与它附近的一个按钮,用户中的一个值,当用户preSS的按钮,我需要执行PHP操作来增加值是显示的按钮(作为一个例子==> myvalue的= 10 |当用户点击该按钮:myvalue的= 11).I've已经构建这一部分,它是工作完美,但我需要增加值,不刷新页面更新MySQL的列?我知道从网上我试过不行其可能的,但每一个教程。

I've build a small login system for a home project,so,when the user do the login,he is redirect to the userspage.php.In the page i get some data from my mysql table,but the problem is,one of the values i fetch is display to the user with a button near it,when the user press those button i need to perform an php action to increase the value which is display with the button(as an example==> myvalue = 10 | When the user clicks on the button: myvalue = 11 ).I've already build this part,it is working perfectly,but i need to increase the value and update the mysql column without refreshing the page?I know its possible but every tutorial from the web i've tried doesn't work.

谢谢你是进步!

推荐答案

以下code有一个按钮,它的onclick电话updatedb.php并显示其在名为结果

The following code has a button which onclick calls updatedb.php and shows its output in div element called 'result'

<html>
<head>
<script type="text/javascript">
function UpdateDb()
{
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("result").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","updatedb.php",true);
xmlhttp.send();
}
</script>


   </head>
    <body>

<button onclick='UpdateDb()'>Update</button>
<p> <span id="result"></span></p>

</body>
</html>

然后写updatedb.php

Then write updatedb.php

<?php
do mysql update here.
and echo the result you want to display.
?>

这篇关于无需重新加载页面更新从MySQL表中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆