Reputation: 2668
I have the following code linked to a PHP file,the objective is to post some strings and retrieve in the PHP file,all the stuff is working fine,but something is wrong with my code,see bellow:
iOS Application Code
NSString *urlString = @"http://www.myurl.com/path/ios.st.addquestion.php?";
NSURL *uploadURL = [NSURL URLWithString:urlString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:uploadURL];
[request setPostValue:askerUsername forKey:@"username"];
[request setPostValue:@"1" forKey:@"questiontype"];
[request setPostValue:title forKey:@"title"];
[request setPostValue:hasAditional forKey:@"hasaditional"];
[request setPostValue:aditional forKey:@"aditional"];
[request setPostValue:hasLocation forKey:@"haslocation"];
[request setPostValue:location forKey:@"location"];
[request setPostValue:latitude forKey:@"latitude"];
[request setPostValue:longitude forKey:@"longitude"];
[request setPostValue:category forKey:@"category"];
[request setPostValue:hasImage forKey:@"hasimage"];
[request startAsynchronous];
PHP File
$questiontype = mysql_real_escape_string($_GET['questiontype']);
$username_PRO = mysql_real_escape_string($_GET['username']);
$title_PRO = mysql_real_escape_string($_GET['title']);
$hasAditional = mysql_real_escape_string($_GET['hasaditional']);
$aditional_PRO = mysql_real_escape_string($_GET['aditional']);
$hasLocation = mysql_real_escape_string($_GET['haslocation']);
$location_PRO = mysql_real_escape_string($_GET['location']);
$latitude_PRO = mysql_real_escape_string($_GET['latitude']);
$longitude_PRO = mysql_real_escape_string($_GET['longitude']);
$category = mysql_real_escape_string($_GET['category']);
echo "$username_PRO";
When i run the application and POST the strings to the PHP file,nothing happens,is like the PHP received a null value,i can't figure out what is wrong in my code,anyone know?The procedure is something like this:
Application => ASIFormDataRequest(Post values) => PHP file receives request and insert strings on a MYSQL database(THE PROBLEM IS HERE).
I have already searched on the web and on ASI website but nothing seems to work.
Upvotes: 0
Views: 198
Reputation: 4702
You are using setPostValue
to a PHP-script
which is looking for GET
variables. Either change your PHPcode
to $username_PRO = mysql_real_escape_string($_POST['username'])
for all your varialbes, or send the values as GET
values with http://url?name=value&name2=value2
...
Upvotes: 1
Reputation: 1739
I think the code is correct, however, you POST to PHP and you use $_GET in php might be the problem.
Try to use $_POST to get the POST value or you can dump $_REQUEST to see what have you sent to your php.
Upvotes: 2