Using $_POST instead of $_GET in php

0 favourites
  • 6 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I'm trying to post a large string variable into a mysql server using php.The php file works fine when the variable isn't too large but due to the limitations of $_GET i need to use $_POST. Here is my php file:

    <?php
    
    $db = "";//Your database name
    $dbu = "";//Your database username
    $dbp = "";//Your database users' password
    $host = "localhost";//MySQL server - usually localhost
    
    $dblink = mysql_connect($host,$dbu,$dbp);
    $seldb = mysql_select_db($db);
    
    if(isset($_GET['arraydata'])){
    
         //Lightly sanitize the GET's to prevent SQL injections and possible XSS attacks
          $arraydata = strip_tags(mysql_real_escape_string($_GET['arraydata']));
         $sql = mysql_query("INSERT INTO `$db`.`scores` (`id`,`arraydata`) VALUES ('','$arraydata')");
         
         if($sql){
         
              //The query returned true - now do whatever you like here.
              echo 'Your score 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 score. 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.
    ?>

    When I switch the $_GET with $_POST nothing is getting posted to the mysql server. Any ideas on how I go about doing this?

  • Did you change the AJAX object to make a POST request instead of a GET request?

  • what Ashley means is:

    -> add Action

    -> choose AJAX

    -> choose "Post to URL"   (not Request URL)

    ps: no offense!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm using the ajax post to url itself, not request. Still not able to figure this out. Any other reason it might not be working?

  • Checked every possible reason and it still isn't working. Really need some help with this.

  • Options:

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

    mysql_real_escape_string adds quotes to the string.

    Try take it out for a test, sometimes, depanding on content, it could break your sql query.

    I see you use auto incrementing IDs, better make sure you set up your database correct. IE id column needs to have AI enabled (auto increment)

    You could perhaps remove `id`   and ``    from your query to make sure, it isnt needed if you have auto increment.

    can you post a capx or a pictue of your ajax call made in c2 ?

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