How do I Update mysql with ajax and php?

0 favourites
  • 4 posts
From the Asset Store
Fantasy Game includes more than 600 sound effects inspired by hit computer games like World of Warcraft and Diablo.
  • To begin i have watched Arcade Ed's videos (thanks Ed!). I can INSERT INTO without issue, echo, and pull info into an array without issue.

    my issue, and I've been stumped for the past 2 days...

    on the php side:

    $a = strip_tags(mysql_real_escape_string($_GET['a']));

    $b= strip_tags(mysql_real_escape_string($_GET['b']));

    $sql = mysql_query("UPDATE table SET a = '$a' WHERE b = '$b'");

    if i go to the browser and change a or b it loads into the database fine, for example:

    http://localhost:8080/doa/bc.php?a=6kala8sh9aaahdhf163s;76;h9dkf1kjkakfdffjj9jafk677f144&b=Bob

    (easily changes by:

    http://localhost:8080/doa/bc.php?a=fjkdlssdlkfslk&b=Tim

    REPEATING: BC.PHP WORKS FINE FROM CHROME BROWSER

    however, when i use construct to send an ajax "POST"...

    "http://localhost:8080/doa/bc.php?a="&Account.ID&"&b="&Account.Username

    nothing happens. It's the exact same code, so I have no clue why this isn't working.

    Oddly enough, I can easily change bc.php to INSERT INTO and it works fine from construct but it creates a new row [due to auto increment] or overwrites my existing fields (which I don't want to happen)...any thoughts?

  • Your PHP is probably fine. It is probably because of security measures that Construct takes seriously that most others don't.

    You will want to add the " Access-Control-Allow-Origin: * " header to your server response in order for Construct to work nicely with the AJAX.

    Make sure you remove that header again when you go live.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • gumshoe, thanks for your response!...turns out I'm just a moron!!!!!! sigh...

    I just happened to test a blank user name on the database to see if i could pass all the data and only half passed...turns out that when I switched layers it was deleting my sprite and creating a new one with empty variables (needed to update the database). Fixed that and it works fine.

    Basically I learned, if the php is working on URL it should work fine with construct.

    Case closed.

  • Glad that you got it fixed. 95% of my bugs are simple and stupid stuff like that too. Yea, I always test my API fully on a browser before I ever go to C2.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)