Headers
# import
@ Interface kiksyloginViewController: UIViewController {
IBOutlet UITextField * usernameField;
IBOutlet UITextField * passwordField;
IBOutlet UIButton * loginButton;
}
@ Property (nonatomic, retain) UITextField * usernameField;
@ Property (nonatomic, retain) UITextField * passwordField;
@ Property (nonatomic, retain) UIButton * loginButton;
- (IBAction) login: (id) sender;
@ End
Implementation file
# import "kiksyloginViewController.h"
@ Implementation kiksyloginViewController
@ Synthesize usernameField;
@ Synthesize passwordField;
@ Synthesize loginButton;
- (IBAction) login: (id) sender
{
NSString * post = [NSString stringWithFormat: @ "username =% @ & password =% @", usernameField.text, passwordField.text];
NSString * hostStr = @ "http://localhost/userlogin.php";
hostStr = [hostStr stringByAppendingString: post];
NSData * dataURL = [NSData dataWithContentsOfURL: [NSURL URLWithString: hostStr]];
NSString * serverOutput = [[NSString alloc] initWithData: dataURL encoding: NSASCIIStringEncoding];
if ([serverOutput isEqualToString: @ "Yes"]) {
UIAlertView * alertsuccess = [[UIAlertView alloc] initWithTitle: @ "Congrats" message: @ "You are authorized"
delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil, nil];
[Alertsuccess show];
[Alertsuccess release];
} Else {
UIAlertView * alertsuccess = [[UIAlertView alloc] initWithTitle: @ "Error" message: @ "Username or Password Incorrect"
delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil, nil];
[Alertsuccess show];
[Alertsuccess release];
}
}
- (Void) didReceiveMemoryWarning {
/ / Releases the view if it doesn't have a superview.
[Super didReceiveMemoryWarning];
/ / Release any cached data, images, etc that aren't in use.
}
- (Void) viewDidUnload {
/ / Release any retained subviews of the main view.
/ / E.g. self.myOutlet = nil;
}
- (Void) dealloc {
[Super dealloc];
}
@ End
PHP file
/ / $ Container = new Container;
$ U = $ _GET ['username'];
$ Pw = $ _GET ['password'];
$ Check = "select username, password from user where username = '$ u' and password = '$ pw'";
function myDbconn ()
{
mysql_connect ("localhost", "root", "") or die ();
mysql_select_db ("test") or die (mysql_error ());
}
myDbconn ();
$ Login = mysql_query ($ check) or die (mysql_error ());
/ / $ Run = DB () -> select ($ check);
if (mysql_num_rows ($ login) == 1) {
/ / $ Row = DB () -> fetch ($ run);
/ / $ Row = DB () -> fetch ($ login);
$ Row = mysql_fetch_assoc ($ login);
echo 'yes';
exit;
}
else {
echo 'No';
exit;
}
?>
Reply:
Server test is not a problem?
Reply:
I suggest you look at NSURLConnection and use NSHttpURLRequest you use on this server is the GET form,
So the title of this post should be called iPhone network connection problem,
Reply:
serverOutput return value is "yes", not a "Yes"
Reply:
Yes changed to yes on the line, I passed the test ~
To the point it ~
Reply:
The
@ "Username =% @ & password =% @"
Changed
@ "? Username =% @ & password =% @"
No comments:
Post a Comment