DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Updating a mySql db with xhr

  1. #1
    Join Date
    Mar 2008
    Location
    BELGIUM - East Flanders
    Posts
    174

    Updating a mySql db with xhr

    Hey,

    I'm trieng to update some data in a mySql database with the XMLHttpRequest. I'm pretty new to this, so i don't have any idea where i'm wrong...

    Here i open a php file with xhr.
    PHP Code:
      xmlhttp.open("GET","xhr.php",true);
      
    xmlhttp.send(null);
      
    document.getElementById('A1').innerHTML=xmlhttp.status;
      
    document.getElementById('A2').innerHTML=xmlhttp.statusText;
      
    document.getElementById('A3').innerHTML=xmlhttp.responseText
    This is the contents of my php file:
    PHP Code:
    <?php
    include("../db.php");

    $table_data mysql_query("SELECT * FROM branches WHERE branch_id = 1");
    while(
    $row mysql_fetch_array($table_data))
        {
        echo 
    "old data: ".$row[branch_views];
        
    $oldVal $row[branch_views];
        }

    $newVal $oldVal 1;

    mysql_query("UPDATE `branches` SET `branch_views` = $newVal WHERE branch_id = 1");

    echo 
    "<br />";

    $table_data mysql_query("SELECT * FROM branches WHERE branch_id = 1");
    while(
    $row mysql_fetch_array($table_data))
        {
        echo 
    "new data: ".$row[branch_views];
        }

    ?>
    When viewing the php file directly, the numbers will increase each time i reload the page, but when getting the contents via xhr, it'll just remain thesame

    How do i solve this?

    Thnx in advence

  2. #2
    Join Date
    Mar 2008
    Location
    BELGIUM - East Flanders
    Posts
    174
    solved, should have used the .open method

Similar Threads

  1. connect VB to mySql
    By jessy in forum Database
    Replies: 3
    Last Post: 12-14-2005, 12:10 PM
  2. MySql help Request
    By airrazor in forum Database
    Replies: 6
    Last Post: 10-04-2005, 04:00 PM
  3. Date/Time Data Type
    By felix in forum ASP.NET
    Replies: 2
    Last Post: 04-05-2002, 06:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center