How do I Update mysql with ajax and php?

Get help using Construct 2

Post » Fri Oct 21, 2016 8:34 pm

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?
B
11
S
2
Posts: 33
Reputation: 651

Post » Sat Oct 22, 2016 3:11 pm

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.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Sat Oct 22, 2016 4:01 pm

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.
B
11
S
2
Posts: 33
Reputation: 651

Post » Sun Oct 23, 2016 3:58 pm

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.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, RobertMKD, Syazanie Amirin and 10 guests