0

As title

here its my codes

h.file

#define kPostURL @"http://localhost/discuss.php"
#define kName @"name"
#define kMessage @"message"
#define kNum @"num"

@interface TestDisViewController : UIViewController{

IBOutlet UITextField *nameText;
IBOutlet UITextView *messageText;
NSURLConnection *postConnection;

UILabel *bbb;
}

@property(strong, nonatomic)IBOutlet UILabel *bbb;
-(IBAction)post:(id)sender;
@property(weak) NSString *aaa;

@end

and m.file

"aaa" is the string that segue from another viewcontroller

#import "TestDisViewController.h"
#import "EatDiscussViewController.h"
@implementation TestDisViewController

@synthesize aaa;
@synthesize bbb =bbb;


-(void) postMessage:(NSString*) message Name:(NSString *) name withNum:(NSString *) num{


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

    NSMutableString *postString = [NSMutableString stringWithString:kPostURL];
    [postString appendString:[NSString stringWithFormat:@"?%@=%@", kName, name]];
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kMessage, message]];
    [postString appendString:[NSString stringWithFormat:@"#%@=%@", kNum, num]];
    [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];

}

- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Taaaaaaaaab:%@",aaa);
self.bbb.text=aaa;
}

}

-(IBAction)post:(id)sender{

[self postMessage:messageText.text Name:nameText.text withNum:bbb.text];
[messageText resignFirstResponder];
messageText.text = nil;
nameText.text = nil;
bbb.text=nil;
[self.navigationController popViewControllerAnimated:YES];

}

@end

i delete some codes that doesn't need to use~

and finally my php.code


@mysql_select_db($database) or die("Error");

$user_name = $_GET["name"];

$commentary = $_GET["message"];

$stores_num = $_GET["num"];

$query = "INSERT INTO comment VALUES ('', '$stores_num' , '$user_name' , '$commentary')";

mysql_query("SET NAMES 'utf8'");

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

mysql_close();

i can pass two values to database

but i cant pass three values........

plz help me!!

4

2 に答える 2

1

エラー: [postString appendString:[NSString stringWithFormat:@"#%@=%@", kNum, num]];

修復:[postString appendString:[NSString stringWithFormat:@"&%@=%@", kNum, num]];

于 2012-11-15T06:55:21.317 に答える
0
$user_name = $_GET["name"]; 
$commentary = $_GET["message"]; 
$stores_num = $_GET["num"]; 

$query = "INSERT INTO comment VALUES ('', '$stores_num' , '$user_name' , '$commentary')"

クエリにフィールドをリストしない場合、それらは必ずしも期待した順序で追加されるとは限りません。フィールド名を明示的に追加してみてください。

$query = "INSERT INTO comment (num, stores_num, user_name, commentary) VALUES ('', '$stores_num' , '$user_name' , '$commentary')"

numが自動インクリメントフィールドの場合、それも必要ありません。

$query = "INSERT INTO comment (stores_num, user_name, commentary) VALUES ('$stores_num' , '$user_name' , '$commentary')"

でも

関数を使用していmysql_*ますが、これらは非推奨になっています。PDOまたはに移動することを検討する必要がありますmysqli_。どちらも、より安全なコードを作成するのに役立ちます。

于 2012-09-15T14:48:34.637 に答える