login program in Xcode using php and mysql is not working

please delete me

hi i am doing login page in my app.i get error in console and invalid message. help me to fined result.thanks in advance. my Xcode is here

- (IBAction)login:(id)sender {

NSInteger success = 0;
@try {

    if([[self.username text] isEqualToString:@""] || [[self.password text] isEqualToString:@""] ) {

        [self alertStatus:@"Please enter Email and Password" :@"Sign in Failed!" :0];

    } else {
        NSString *post =[[NSString alloc] initWithFormat:@"username=%@&password=%@",[self.username text],[self.password text]];
        NSLog(@"PostData: %@",post);

        NSURL *url=[NSURL URLWithString:@"http://192.168.1.5:81/priya/login.php"];

        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

        NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];

        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
        [request setURL:url];
        [request setHTTPMethod:@"POST"];
        [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
        [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        [request setHTTPBody:postData];

        //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];

        NSError *error = [[NSError alloc] init];
        NSHTTPURLResponse *response = nil;
        NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

        NSLog(@"Response code: %ld", (long)[response statusCode]);

        if ([response statusCode] >= 200 && [response statusCode] < 300)
        {
            NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
            NSLog(@"Response ==> %@", responseData);

            NSError *error = nil;
            NSDictionary *jsonData = [NSJSONSerialization
                                      JSONObjectWithData:urlData
                                      options:NSJSONReadingMutableContainers
                                      error:&error];

            success = [jsonData[@"success"] integerValue];
            NSLog(@"Success: %ld",(long)success);

            if(success == 1)
            {
                NSLog(@"Login SUCCESS");
            } else {

                NSString *error_msg = (NSString *) jsonData[@"error_message"];
                [self alertStatus:error_msg :@"Sign in Failed!" :0];
            }

        } else {
            //if (error) NSLog(@"Error: %@", error);
            [self alertStatus:@"Connection Failed" :@"Sign in Failed!" :0];
        }
    }
}
@catch (NSException * e) {
    NSLog(@"Exception: %@", e);
    [self alertStatus:@"Sign in Failed." :@"Error!" :0];
}
if (success) {
    [self performSegueWithIdentifier:@"login_success" sender:self];
}}

and my php coding

<?php

$host = "localhost"; 
$user = "xcode"; 
$pass = "xcode"; 
$db="xcode";

$r = mysql_connect($host, $user, $pass);

if (!$r) {
    echo "Could not connect to server\n";
    trigger_error(mysql_error(), E_USER_ERROR);
} else {
    echo "Connection established\n"; 
}

echo mysql_get_server_info() . "\n"; 
$r2 = mysql_select_db($db);

if (!$r2) {
    echo "Cannot select database\n";
     trigger_error(mysql_error(), E_USER_ERROR);
} else {
    echo "database selected\n"; 
}
$u=$_POST['username'];
$pw=$_POST['password'];
$result=mysql_query("select username,password from login where username='$u' and      password='$pw'");

$row=mysql_fetch_array($result);
if($row["username"]==$u && $row["password"]==$pw)
{
echo '{"success":1}';
}
else
{
 '{"success":0,"error_message":"Username and/or password is invalid."}';
 }

  mysql_close();
  ?>

and i got result in console

2014-02-22 13:44:48.172 school apps[1605:a0b] PostData: username=admin&password=xcode
2014-02-22 13:44:49.252 school apps[1605:a0b] Response code: 200
2014-02-22 13:44:49.252 school apps[1605:a0b] Response ==> Connection established
5.5.34
database selected
{"success":1}
2014-02-22 13:44:49.253 school apps[1605:a0b] Success: 0

if any tutorial is there means give me url.i am very new to Xcode.

Gokhan Dilek

You need to convert the mySQL database output to json format.

   //set the mime type
   $document->setMimeEncoding('application/json');
   echo json_encode($yourdata);

Once converted, you need

    jexit();

to exclude the html in the source code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Login with Phonegap, AJAX, PHP and mySQL not working

From Dev

PHP and MySQL Login/Register System Not Working

From Dev

Login system using PHP myadmin not working

From Dev

Facebook Login using PHP SDK not working

From Dev

How to create a simple login in php using mySQL

From Dev

How to create a simple login in php using mySQL

From Dev

Php login "Invalid username and password" using mysql

From Dev

Inserting Data to MySQL using PDO for PHP Xcode

From Dev

My php/mysql script is not working when trying to login

From Dev

Login code not working in PHP

From Dev

PHP login forms not working

From Dev

PHP Login and Logout not working

From Dev

Submit button not working on login form, using PHP and JavaScript

From Dev

PDO Insert operation using PHP and MYSQL not working

From Dev

AND operator not working in a PHP function using MySQL

From Dev

Login using ajax not working

From Dev

Redirect View login using xcode

From Dev

Redirect View login using xcode

From Dev

Login using JQuery, PHP and MySQL data validation issue

From Dev

PHP login using details from two mysql tables

From Dev

Can not Make Android Login Using PHP, MySQL and Volley

From Dev

How to fetch last login datetime using PHP and MySQL database?

From Dev

php and MySQL Login system

From Dev

PHP MySQL Login Failure

From Dev

php mysql login issue

From Dev

php login system - login does not working

From Dev

Using Xcode to debug cpp program

From Dev

How to program a recurring billing/invoice system using PHP and MySQL

From Dev

Unable to fetch MySQL row data using PHP Program