gars, je veux poster des données sur le serveur web, comme nom d'utilisateur et mot de passe, sur le serveur web, j'ai utilisé PHP pour écho oui ou non, j'ai joint tout le code. Quelqu'un peut-il m'aider, quel est le problème avec le code. Comme il est toujours dit mot de passe incorrect ou nom d'utilisateur. J'ai essayé de tester le code php avec le nom d'utilisateur et le mot de passe à l'intérieur, ça fonctionne. Alors s'il vous plaît aidez-moi. Je vous remercie.Iphone sdk, Comment poster des données au serveur web? quelqu'un a un exemple?
fichier d'en-tête
@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
fichier de mise en œuvre
#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
fichier PHP
<?php
//$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;
}
?>