数据库集成用户注册w/php

数据库集成用户注册w/php,php,mysql,objective-c,Php,Mysql,Objective C,是否有人可以发布一些代码,只需将一行数据发布到数据库,然后将一行数据读回Xcode中查看?我有一个基本的PHP文件和我一直在玩的Xcode项目,它更新了我数据库中的一行,但信息在这两个字段中都是空白的 PHP代码减去域和主机信息: <?php $username = "Username"; $pass = "Password"; $database = "test"; mysql_connect('localhost', $username, $pass); @mysql_selec

是否有人可以发布一些代码,只需将一行数据发布到数据库,然后将一行数据读回Xcode中查看?我有一个基本的PHP文件和我一直在玩的Xcode项目,它更新了我数据库中的一行,但信息在这两个字段中都是空白的

PHP代码减去域和主机信息:

<?php

$username = "Username";
$pass = "Password";
$database = "test";

mysql_connect('localhost', $username, $pass);

@mysql_select_db($database) or die ("Unable to find database");

$name = @$_POST["name"];
$message = @$_POST["message"];

$query = "INSERT INTO test VALUES ('', '$name', '$message')";

mysql_query($query) or die (mysql_error("error"));

mysql_close();

?>
.m文件

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad {
[super viewDidLoad];

}




-(void) postMessage:(NSString*) message withName:(NSString *) name{

if(name !=nil && message !=nil){

     NSMutableString *postString = [NSMutableString          stringWithString:kPostURL];
    [postString appendString:[NSString stringWithFormat:@"?%@=%@", kName, name]];

     [postString appendString: [NSString stringWithFormat:@"&%@=%@", kMessage, message]];

    [postString setString:[postString         stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSMutableURLRequest *request =[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: postString]];


     [request setHTTPMethod:@"POST"];

     postConnection =[[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];


 }
 }

 -(IBAction)post:(id)sender{
 [self postMessage:messageText.text withName:nameText.text];
[messageText resignFirstResponder];
 messageText.text=nil;
 nameText.text=nil;}




  - (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning];

 }


 @end

如果有人能用Xcode 7.2和swift 2更好地做到这一点,我愿意在可能的情况下进行转换。

为什么你的标题上写着“swift 2”但是你的问题包含一堆Objective-C代码?我找不到任何可以在swift 2中使用的代码,所以我必须使用Objective C来看看我是否至少可以使用它。我想如果我可以在那里获得数据,我可以在以后担心验证和安全性。
#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad {
[super viewDidLoad];

}




-(void) postMessage:(NSString*) message withName:(NSString *) name{

if(name !=nil && message !=nil){

     NSMutableString *postString = [NSMutableString          stringWithString:kPostURL];
    [postString appendString:[NSString stringWithFormat:@"?%@=%@", kName, name]];

     [postString appendString: [NSString stringWithFormat:@"&%@=%@", kMessage, message]];

    [postString setString:[postString         stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSMutableURLRequest *request =[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: postString]];


     [request setHTTPMethod:@"POST"];

     postConnection =[[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];


 }
 }

 -(IBAction)post:(id)sender{
 [self postMessage:messageText.text withName:nameText.text];
[messageText resignFirstResponder];
 messageText.text=nil;
 nameText.text=nil;}




  - (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning];

 }


 @end