目前在做用户登录,需要把用户名和密码发到服务器验证,服务器端用PHP接受,测试了好久,就是不能发送,我把全部代码都贴出来了,大家看看啦。头文件
#import <UIKit/UIKit.h>@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实现文件
#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];
}@endPHP 文件
<?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; 
} ?>