Mohammed Imran Mohammed Imran - 1 year ago 73
PHP Question

Sending empty data PHP Url

NSString *email = cusemail.text;
NSString *pass = cuspassword.text;
NSString *noteDataString = [NSString stringWithFormat:@"http://domain/Customer_logon.php?email=%@&password=%@",email,pass];

NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];

NSURL * url = [NSURL URLWithString:@""];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[noteDataString dataUsingEncoding:NSUTF8StringEncoding]];

NSURLSessionDataTask * dataTask =[defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *dataRaw, NSURLResponse *header, NSError *error) {
NSDictionary *json = [NSJSONSerialization
options:kNilOptions error:&error];
NSString *status = json[@"status"];

if([status isEqual:@"1"]){

} else {


$dbhost = "localhost";
$dbuser = "zzzz";
$dbpassword = "zzz";
$dbname = "zzzz";
$email = isset($_GET['email']);
$Password = isset($_GET['password']);

$connection = mysqli_connect($dbhost, $dbuser, $dbpassword,$dbname);

if (mysqli_connect_errno())
die("Database Connection failed: ". mysqli_connect_error()."(".

// A higher "cost" is more secure but consumes more processing power
$cost = 10;

// Create a random salt
$salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');

// Prefix information about the hash so PHP knows how to verify it later.
// "$2a$" Means we're using the Blowfish algorithm. The following two digits are the cost parameter.
$salt = sprintf("$2a$%02d$", $cost) . $salt;

printf("printing salt".$salt);

// Value:
// $2a$10$eImiTXuWVxfM37uY4JANjQ==

// Hash the password with the salt
$hash = crypt($Password, $salt);

printf("printing password".$hash);

$query = "INSERT INTO customer_logon(Email, Password) VALUES ('{$email}', '{$Password}')";

$result_customer_logon = mysqli_query($connection, $query);

printf("Errormessage: ".mysqli_error($connection));


I'm executing the above peace of code from Xcode PHP is receiving empty data.
I'm actually trying to take to fields from the user and inserting them to MySql database after executing this code I'm getting Empty field in the table but, Column is getting created in the table there email and password column are empty.

Answer Source
[urlRequest setHTTPBody:[noteDataString dataUsingEncoding:NSUTF8StringEncoding]];

this method can set the data you want to send to your server. your server received a string "http://domain/Customer_logon.php? email=XXXX&password=XXXX",the string is not a valid json, your php can not parse it.

so,if you need a json,you can write like this:

NSString *email = cusemail.text;
NSString *pass  = cuspassword.text;
NSDictionary *dic = @{@"email":email,@"password":pass};
[urlRequest setHTTPBody:[NSJSONSerialization dataWithJSONObject:dic options:0 error:nil]];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download