doulanli6146 2012-04-14 21:40
浏览 103
已采纳

从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.

Thanks is advance!

  • 写回答

2条回答 默认 最新

  • dongwujie7477 2012-04-14 22:28
    关注

    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>
    

    Then write updatedb.php

    <?php
    do mysql update here.
    and echo the result you want to display.
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答