比较来自世界各地的卖家的域名和 IT 服务价格

Iphone sdk, 如何在Web服务器上放置数据? 有人有一个例子吗?

伙计们,我想向Web服务器发送数据,例如用户名和密码,我在Web服务器上使用 PHP 对于echo,是或否,我附上了所有代码。 有人可以帮助我没有代码。 由于他总是说错误的密码或用户名。 我试图检查代码 php 使用内部用户名和密码,它有效。 所以请帮帮我。 谢谢。

标题文件


@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 = @"[url=http://localhost/userlogin.php";]http://localhost/userlogin.php";[/url]
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 文件


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;
}

?>
已邀请:

三叔

赞同来自:

第一个问题我认为可能是最大的事情是没有"?". 特别是,这是:


@"username=%@&password=%@"


必须更像这样:


@"?username=%@&password=%@"


由于您没有将消息发送到服务器,因此您只需使用请求 GET 和参数 URL.

我不知道你是否计划获得Web服务器 PHP, 在后台上工作,但在某些时候我猜你改变了 http://localhost 在别的东西上,我希望你清除你的要求。 SQL, 在允许人们访问您的网页并在请求中输入他们想要的一切。 URL.

詹大官人

赞同来自:

帖子老,但仍然,如果他可以帮助别人:

是的,有一对错误。 首先,文件中的正确行 .m 一定是:


NSString *post =[NSString stringWithFormat:@"?&username=%@&password=%@",
usernameField.text, passwordField.text];


也在文件中。 m:


if/[serverOutput isEqualToString:@"yes"]/{


反而 "Yes". 小心大写字母!

一切都。 代码效果良好。

要回复问题请先登录注册