Comments (135)

  1. Gokul

    HI,
    It works fine if i use your webservices. i do have another web service
    “”,”error_message”=>””);
    if ($con) {
    //echo “connected” . “”;
    } else {
    //echo “not connected” . “”;
    }
    $json = array();

    $username = $_GET[“username”];
    $password = $_GET[“password”];

    $image=mysqli_query($con,”Select * from login where username=’$username’ and password=’$password'”);

    $row_count=mysqli_num_rows($image);
    if ($row_count>0)
    {
    $data[“error_code”] =1000;
    $data[“error_message”]=”Success”;
    print json_encode($data);
    }
    else
    {
    $data[“error_code”] = 1001;
    $data[“error_message”] = “Username or Password is wrong”;
    print json_encode($data);
    }
    mysqli_close($con);
    ?>

    it works fine in postman client
    but not working in the simulator why?

    can u help me?

    Thanks in advance

  2. Manish

    Thanks !!
    i followed many tutorial but your tutorial works ..
    its easy to understand json
    Thanks

  3. Paulo Cesar

    Thanks for this tutorial. I was able to add a login screen to a existent project and it run smooth in the first try!

  4. Fatimah

    Hi i have downloaded the source code nd everything was working fine until i entered the username and password details. It says signing failed, does the following code have to be pasted in php:

    Also how would i link the iOS app to my phpAdmin

    thank you

  5. I believe you are missing the quotes around the query.
    $query = “SELECT * FROM User WHERE username = ‘$username’ AND Password = ‘$password'”;

  6. HAIDER

    HI it says there is a t-string syntax error on line 14 … $query = SELECT * FROM User WHERE username = ‘$username’ AND Password = ‘$password’; i am really stuck

    —CODE PHP FILE BELOW—

    //Retrieve the login details via POST
    $username = $_POST[‘username’];
    $password = $_POST[‘password’];

    //Query the table
    $query = SELECT * FROM User WHERE username = ‘$username’ AND Password = ‘$password’;

    //check if results are returned
    $num = mysql_num_rows($query);

    //if a record found matching query
    if ($num == 1)
    {
    echo ‘{“success”:1}’;
    }
    else
    {
    echo ‘{“success”:0,”error_message”:”Username and/or password is invalid.”}’;
    }
    mysql_close();

    ?>

  7. Meenakshi

    Hi,

    I am being sent to the Home view even if login is incorrect. I tried dragging the segue from the whole view. but I still face the same issue.

  8. Ashiqur

    I dipin having issue with my program when I log in it it goes back to xcode then shows me an issue.

  9. Giovana

    Hi Dipin, great tutorial!

    I’m new to iOS development, and I’m trying to get the login informations from a database, so how can I do it using PHP?

  10. Sarbo

    Great video but my question is when I replace the link with my own website with the same file I get an Access denied error how can i fix that?

  11. Matt Filer

    Thanks so much for this tutorial, been looking everywhere for something like this!

  12. Alex

    Hi

    My app will be use by more then one person, how do I get the php file to allow more usernames and passwords.

    Thanks

  13. Ben

    Thanks Dipin Krishna,

    This is just what I needed to know to begin my project. I am a PHP developer and coming to Objective-C is very odd and hard to get to grips with.

    Thanks, much appreciated! 🙂

  14. Justin

    Dont know how I missed that. Thank you Dipin, awesome tut and working like a champ.

  15. Justin

    Just figured it out and was being a idiot, this was my problem. I assigned Post = username and not username = POST. Fixed it now and this is the final PHP code to do validate checking on a database.

    //Retrieve the login details via POST
    $username = $_POST[‘username’];
    $password = $_POST[‘password’];

    //Query the table
    $query = mysql_query(“SELECT * FROM CFP WHERE Email = ‘$username’ AND Password = ‘$password'”);

    //check if results are returned
    $num = mysql_num_rows($query);

    //if a record found matching query
    if ($num == 1)
    {
    echo ‘{“success”:1}’;
    }
    else
    {
    echo ‘{“success”:0,”error_message”:”Username and/or password is invalid.”}’;
    }
    mysql_close();

    I have now got it to login but when its correct details the application crashes with this error:

    2014-09-04 19:38:26.728 CrossfitPotch[41414:60b] PostData: username=j@cfp.com&password=admin
    2014-09-04 19:38:26.757 CrossfitPotch[41414:60b] Response code: 200
    2014-09-04 19:38:26.757 CrossfitPotch[41414:60b] Response ==> {“success”:1}
    2014-09-04 19:38:26.757 CrossfitPotch[41414:60b] Success: 1
    2014-09-04 19:38:26.758 CrossfitPotch[41414:60b] Login SUCCESS
    2014-09-04 19:38:26.760 CrossfitPotch[41414:60b] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Receiver () has no segue with identifier ‘login_success”
    *** First throw call stack:
    (
    0 CoreFoundation 0x017f31e4 __exceptionPreprocess + 180
    1 libobjc.A.dylib 0x015728e5 objc_exception_throw + 44
    2 UIKit 0x0035348c -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0
    3 CrossfitPotch 0x0000356b -[LoginViewController signinClicked:] + 3051
    4 libobjc.A.dylib 0x01584880 -[NSObject performSelector:withObject:withObject:] + 77
    5 UIKit 0x002343b9 -[UIApplication sendAction:to:from:forEvent:] + 108
    6 UIKit 0x00234345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    7 UIKit 0x00335bd1 -[UIControl sendAction:to:forEvent:] + 66
    8 UIKit 0x00335fc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
    9 UIKit 0x00335243 -[UIControl touchesEnded:withEvent:] + 641
    10 UIKit 0x00273ddd -[UIWindow _sendTouchesForEvent:] + 852
    11 UIKit 0x002749d1 -[UIWindow sendEvent:] + 1117
    12 UIKit 0x002465f2 -[UIApplication sendEvent:] + 242
    13 UIKit 0x00230353 _UIApplicationHandleEventQueue + 11455
    14 CoreFoundation 0x0177c77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    15 CoreFoundation 0x0177c10b __CFRunLoopDoSources0 + 235
    16 CoreFoundation 0x017991ae __CFRunLoopRun + 910
    17 CoreFoundation 0x017989d3 CFRunLoopRunSpecific + 467
    18 CoreFoundation 0x017987eb CFRunLoopRunInMode + 123
    19 GraphicsServices 0x037e75ee GSEventRunModal + 192
    20 GraphicsServices 0x037e742b GSEventRun + 104
    21 UIKit 0x00232f9b UIApplicationMain + 1225
    22 CrossfitPotch 0x0000277d main + 141
    23 libdyld.dylib 0x01e3a701 start + 1
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    (lldb)

  16. Justin

    This is the code from the debug console.

    2014-09-04 19:25:00.449 CrossfitPotch[40463:60b] PostData: username=j@cfp.com&password=admin
    2014-09-04 19:25:00.480 CrossfitPotch[40463:60b] Response code: 200
    2014-09-04 19:25:00.481 CrossfitPotch[40463:60b] Response ==>
    Notice: Undefined variable: POST in /Applications/XAMPP/xamppfiles/htdocs/Justin_Test/LoginTest.php on line 22

    Notice: Undefined variable: username in /Applications/XAMPP/xamppfiles/htdocs/Justin_Test/LoginTest.php on line 26
    {“success”:0,”error_message”:”Username and/or password is invalid.”}
    2014-09-04 19:25:00.481 CrossfitPotch[40463:60b] Success: 0

  17. Justin

    If i hard code the PHP file and set the post varibles to the user and pass then it does yes, else if i leave it as it i get a Unidentified index error if i try open the PHP, which is likely due to the varibles having no set values yet from the program.

  18. Justin

    Need a bit of assistance, im linking this to a mySQL database and have everything up and running fine on the xcode side but my php file wont seem to work with some modifying.

    //MY PHP FILE CODE
    $host = “localhost”; //Your database host server
    $db = “CrossfitPotch”; //Your database name
    $user = “root”; //Your database user
    $pass = “root”; //Your password

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

    //Check to see if we can connect to the server
    if(!$connection)
    {
    die(“Database server connection failed.”);
    }
    else
    {
    //Attempt to select the database
    $dbconnect = mysql_select_db($db, $connection);

    //Retrieve the login details via POST
    $_POST[‘username’] == ‘j@cfp.com’;
    $password = $POST[‘password’];

    //Query the table
    $query = mysql_query(“SELECT * FROM CFP WHERE Email = ‘$username’ AND Password = ‘$password'”);

    //check if results are returned
    $num = mysql_num_rows($query);

    //if a record found matching query
    if ($num == 1)
    {
    echo ‘{“success”:1}’;
    }
    else
    {
    echo ‘{“success”:0,”error_message”:”Username and/or password is invalid.”}’;
    }
    mysql_close();
    }

    No matter what details I type back it will never carry onto the next story. I am trying to do this due to the fact that I have multiple users Id like to make in the end product.

  19. You can use NSUserDefaults.

    Saving:

    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
     
    // saving an NSString
    [prefs setObject:@"TEXT" forKey:@"keyToLookup"];
     
    // saving an NSInteger
    [prefs setInteger:99 forKey:@"integerKey"];
     
    // saving a Double
    [prefs setDouble:1.234 forKey:@"doubleKey"];
     
    // saving a Float
    [prefs setFloat:1.2345678 forKey:@"floatKey"];
     
    [prefs synchronize];

    Retrieving:

    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
     
    // getting an NSString
    NSString *myString = [prefs stringForKey:@"keyToLookup"];
     
    // getting an NSInteger
    NSInteger myInt = [prefs integerForKey:@"integerKey"];
     
    // getting an Float
    float myFloat = [prefs floatForKey:@"floatKey"];
  20. Andrei Popescu

    Found the problem. It was the URL. I have a 301 redirection for www on the link and it was not working becuase of that. I’ve add www on the url and now is working.

    Can you please tell me how to push data from this request back to home screen?

Leave a comment

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.