PHP database connection help

0 favourites
  • 3 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • $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

  • Ah, excellent. Thanks. I was hoping it was just a silly little mistake on my part! Working now

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