PHP database connection help

Get help using Construct 2

Post » Fri Jan 10, 2014 1:03 pm

Hello folks. I'm working on a little promotional game for a client. the game is working and I just need to add a feature that takes an input from the player and adds it to a database. I've followed the arcade ed tutorial on high score tables and that is working, now I'm trying to modify the PHP to accept some more variables. They are: Name, email, phone number and 2 booleans, one called 'car' and one called 'insurance'.

I know nothing about php so it's just trial and error and I thought I'd reach out to try and see if someone could help me on this. Here's my PHP file for saving the data so far (I've edited out my login details):



<?php


$db = "database";//Your database name
$dbu = "user";//Your database username
$dbp = "pass";//Your database users' password
$host = "localhost";//MySQL server - usually localhost

$dblink = mysql_connect($host,$dbu,$dbp);
$seldb = mysql_select_db($db);

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

     //Lightly sanitize the GET's to prevent SQL injections and possible XSS attacks
     $name = strip_tags(mysql_real_escape_string($_GET['name']));
     $email = strip_tags(mysql_real_escape_string($_GET['email']));
      $phone = strip_tags(mysql_real_escape_string($_GET['phone']));
      $car = strip_tags(mysql_real_escape_string($_GET['car']));
      $insurance = strip_tags(mysql_real_escape_string($_GET['insurance']));
     
     $sql = mysql_query("INSERT INTO `$db`.`scores` (`id`,`name`,`email`,`phone`,`car`,`insurance`) VALUES ('','$name','$email','phone','car'','insurance');");
     
     if($sql){
     
          //The query returned true - now do whatever you like here.
          echo 'Your information was saved. Congrats!';
          
     }else{
     
          //The query returned false - you might want to put some sort of error reporting here. Even logging the error to a text file is fine.
          echo 'There was a problem saving your information. Please try again later.';
          
     }
     
}else{
     echo 'Your name or score wasnt passed in the request. Make sure you add ?name=NAME_HERE&score=1337 to the tags.';
}

mysql_close($dblink);//Close off the MySQL connection to save resources.
?>


Thanks in advance to anyone who can assist.
B
12
S
1
Posts: 34
Reputation: 677

Post » Fri Jan 10, 2014 1:44 pm

   $sql = mysql_query("INSERT INTO `$db`.`scores` (`id`,`name`,`email`,`phone`,`car`,`insurance`) VALUES ('','$name','$email','phone','car','insurance')");


removed roque semiclon and some misplaced qoute
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,552

Post » Fri Jan 10, 2014 1:52 pm

Ah, excellent. Thanks. I was hoping it was just a silly little mistake on my part! Working now
B
12
S
1
Posts: 34
Reputation: 677


Return to How do I....?

Who is online

Users browsing this forum: Magistross, mtnboy22, Rable and 6 guests