This is my objective c coding for database connection
- (IBAction) login: (id) sender
{
NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",userna meField.text, passwordField.text];
NSString *hostStr = @"iPhoneconnection.php?";
hostStr = [hostStr stringByAppendingString

ost];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if([serverOutput isEqualToString=="Yes"]){
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"success" message:@"You are authorized"
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alertsuccess show];
[alertsuccess release];
} else {
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Fail" message:@"Invalid Access"
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alertsuccess show];
[alertsuccess release];
}
loginButton.enabled = FALSE;
}
This is my php script
<?php
$con = mysql_connect("localhost","root","root");
if(!$con)
{
die('Could not connect: ' .mysql_error());
}
mysql_select_db("iPhoneconnection",$con);
?>
<?php
session_start();
$u = $_POST['username'];
$pw = $_POST['password'];
$check = "SELECT username, password FROM iphoneusers WHERE username='$u' AND password= '$pw'";
$login = mysql_query($check, $con) or die(mysql_error());
if (mysql_num_rows($login) == 1) {
$row = mysql_fetch_assoc($login);
$_SESSION['username']=$u;
echo'login sucess';
header("HTTP/1.1 200 OK");
}
else{
header("403 Forbidden");
}
mysql_close($con);
?>
In objective c the else part alone is getting executed..If you find any errors in the above code kindly let me know....