How do I Update a database?

Get help using Construct 2

Post » Sun Mar 01, 2015 11:00 pm


I have been working with Construct for some time and I'm now lost into tasks getting too difficult for me.
I can make an array from an sql database, and it opens a lot of possibilities, but I'm stuck when it comes to update the database.

Here is the php coding I use to send data to MySQL :

if(isset($_GET['name']) && isset($_GET['score'])){

$name = strip_tags(mysql_real_escape_string($_GET['name']));
$score = strip_tags(mysql_real_escape_string($_GET['score']));
$sql = mysql_query("INSERT INTO `$db`.`scores` (`id`,`name`,`score`) VALUES ('','$name','$score');");

With the Ajax object, we can call an URL like "....?name=NAME_HERE&score=1337" and then make a new line in the Database.

My question is, how to edit/update a particular item. For example if I use this method to make a profile and the player wants to change a line of it...

The index of my database is "id" which is auto_increment. I'm not sure if it helps or not.

I have been watching dozens of tutorials but nothing is working for me. If you have any idea how this would be working I thank you in advance.
Posts: 3
Reputation: 356

Post » Sun Mar 01, 2015 11:37 pm

When the user updates their profile, you will have their id available.

Update score for user id 1
UPDATE `$db`.`scores` set score = 1000 where id = 1;

Update score and name for id 1
UPDATE `$db`.`scores` set name = "bob", score = 1337 where id = 1;

With the url, its basically the same, just make sure to pass the id.

Posts: 317
Reputation: 2,801

Post » Sun Mar 01, 2015 11:39 pm

Hi, this is not a construct issue, you just need to learn sql a bit more.

so I believe (late at night reading) is that what you need to learn is the UPDATE option in combination with the WHERE option.

some links that might be useful
Posts: 181
Reputation: 1,346

Post » Mon Mar 02, 2015 10:34 am

thanks a lot, I will figure out from here, it was very helpfull anyway!
Posts: 3
Reputation: 356

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests