Using $_POST instead of $_GET in php

Get help using Construct 2

Post » Wed Nov 20, 2013 1:07 pm

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:

[code]
<?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.
?>[/code]

When I switch the $_GET with $_POST nothing is getting posted to the mysql server. Any ideas on how I go about doing this?
B
3
Posts: 7
Reputation: 189

Post » Wed Nov 20, 2013 1:42 pm

Did you change the AJAX object to make a POST request instead of a GET request?
Scirra Founder
B
398
S
236
G
88
Posts: 24,433
Reputation: 194,635

Post » Wed Nov 20, 2013 1:56 pm

what Ashley means is:

-> add Action
-> choose AJAX
-> choose "Post to URL"   (not Request URL)

ps: no offense!
B
7
S
3
Posts: 15
Reputation: 1,455

Post » Thu Nov 21, 2013 5:37 am

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?
B
3
Posts: 7
Reputation: 189

Post » Fri Nov 22, 2013 5:36 am

Checked every possible reason and it still isn't working. Really need some help with this.
B
3
Posts: 7
Reputation: 189

Post » Fri Nov 22, 2013 7:06 am

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 ?

Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572


Return to How do I....?

Who is online

Users browsing this forum: Kin, Maydie and 34 guests