0

I am working on a app with a login that connects to a database.

I have this code but i always get the third alert "niks" and i don't know why i am getting this error.

- (void) loginAction{
if ([userNameTextField.text isEqualToString:@""] || [passwordTextField.text isEqualToString:@""]) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Please Fill all the field" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    return;
}

NSString *strURL = [NSString stringWithFormat:@"http://192.168.1.47:8888/swift/login.php?userName=%@&password=%@",userNameTextField.text, passwordTextField.text];


NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];


NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

if ([strResult isEqualToString:@"1"])
{

    AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
    [appDelegate.navigationController popToRootViewControllerAnimated:NO];
    // create object from app main view to push it
    AppMainView *appMainView = [[AppMainView alloc] initWithNibName:@"AppMainView" bundle:nil];
    [appDelegate.navigationController pushViewController:appMainView animated:YES];
}
else if ([strResult isEqualToString:@"0"])
{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Invalide Information" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    return;

}
else {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"niks" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    return;
}




}

and the php code

<?php


if (isset($_GET["userName"]) && isset($_GET["password"])) {
    $userName = $_GET["userName"];
    $password = $_GET["password"];
    $result = login( $userName, $password);
    echo $result;
}

function makeSqlConnection()
{
    $DB_HostName = "localhost";
    $DB_Name = "temp";
    $DB_User = "root";
    $DB_Pass = "root";

    $con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error()); 

    mysql_select_db($DB_Name,$con) or die(mysql_error()); 

    return $con;
}

function disconnectSqlConnection($con)
{
    mysql_close($con);
}

function login($userName, $password)
{
    $con = makeSqlConnection();

    $sql = "select * from user  where userName = '$userName' and password = '$password';";
    $res = mysql_query($sql,$con) or die(mysql_error());

    $res1 = mysql_num_rows($res);

    disconnectSqlConnection($con);

    if ($res1 != 0) {
        return 1;
        echo "1";
    } else {
        return 0;
        echo "0";
    }
}

?>

I have xcode 7.0 and php 5.6.2

borracciaBlu
  • 4,017
  • 3
  • 33
  • 41
Jeroen
  • 432
  • 1
  • 9
  • 20

1 Answers1

1

One piece of code you have is :

or die(mysql_error());

Which it will explains the third alert.

One test you can do it's to call your API in the browser.

http://192.168.1.47:8888/swift/login.php?userName=%@&password=%@
borracciaBlu
  • 4,017
  • 3
  • 33
  • 41
  • it gives me this Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /Applications/MAMP/htdocs/swift/login.php on line 19 0 – Jeroen Aug 23 '15 at 12:41
  • so update it :) http://stackoverflow.com/questions/16531252/replacement-for-deprecated-function-mysql-connect – borracciaBlu Aug 23 '15 at 12:43