1

申し訳ありませんが、これは私の最初の質問です。アプリを作成する学校のプロジェクトを行っていますが、SQL php 接続に問題があります。

データベースに空白を投稿しています。

フォーマットですみません。コード全体は含めず、結果に影響すると思われる領域のみを含めました。

これが私のコードです:

ブッキング.h

#define kPostURL @"http://XXX/app/quickbooking.php"
#define kFirstname @"firstname"
#define kLastname @"lastname"
#define kContactno @"contactno"
#define kEmail @"email"
#define kClub @"club"
#define kDatetime @"datetime"



@interface TellUs : UIViewController <UINavigationControllerDelegate, UIActionSheetDelegate, UITextFieldDelegate,UIPickerViewDataSource, UIPickerViewDelegate,UITextFieldDelegate, SKPSMTPMessageDelegate>{

IBOutlet UITextField *messageText;
IBOutlet UITextField *messageTextName;
IBOutlet UITextField *messageTextLastName;
IBOutlet UITextField *messageTextEmail;
IBOutlet UIButton *doneEditingButton;
IBOutlet UIButton *sendMail;
IBOutlet UILabel *feedbackMsg;
IBOutlet UIDatePicker *myDatePicker;
IBOutlet UITextField *yourTextField;
IBOutlet UIToolbar  *toolBar;
IBOutlet UIBarButtonItem *barButton;
IBOutlet UISegmentedControl *segmentedControl;
IBOutlet UILabel *myDatePickerLabel;
IBOutlet UILabel *myPickerLabel;
IBOutlet UIPickerView *myPicker;
IBOutlet UITextField *yourTextFieldPicker;
IBOutlet UIButton *tellUsWhatYouThink;
NSArray *dataSource;
NSArray *fieldsArray;
CGFloat             animatedDistance;

IBOutlet UIButton *postBooking;
NSURLConnection *postConnection;


}

@property (nonatomic, retain) UITextField *messageText;
@property (nonatomic, retain) UITextField *messageTextName;
@property (nonatomic, retain) UITextField *messageTextLastName;
@property (nonatomic, retain) UITextField *messageTextEmail;
@property (nonatomic, retain) UIButton *doneEditingButton;
@property (nonatomic, retain) UIButton *sendMail;
@property (nonatomic, retain) UILabel *feedbackMsg;
@property (nonatomic, retain) UISegmentedControl *segmentedControl;
@property (nonatomic, retain) UIButton *tellUsWhatYouThink;
@property (nonatomic, retain) UIDatePicker *myDatePicker;
@property (nonatomic, retain) UITextField *yourTextField;
@property (nonatomic, retain) UILabel *myDatePickerLabel;
@property (nonatomic, retain) UILabel *myPickerLabel;
@property (nonatomic, retain) UIPickerView *myPicker;
@property (nonatomic, retain) NSArray *dataSource;
@property (nonatomic, retain) UITextField *yourTextFieldPicker;
@property (nonatomic, retain) IBOutlet UITextView *textView;

@property (nonatomic, retain) UIButton *postBooking;


-(void) postFirstname:(NSString *)firstname withLastname:(NSString *)lastname withContactno:(NSString *)contactno withEmail:(NSString *)email withClub:(NSString *)club withDatetime:(NSString *)datetime;


- (IBAction)postBooking:(id)sender;

@end

Booking.m

@synthesize feedbackMsg;
@synthesize tellUsWhatYouThink;
@synthesize sendMail;
@synthesize doneEditingButton;
@synthesize messageText;
@synthesize messageTextName;
@synthesize messageTextLastName;
@synthesize messageTextEmail;
@synthesize myDatePicker, yourTextField, segmentedControl;
@synthesize myDatePickerLabel;
@synthesize myPickerLabel, myPicker, dataSource;
@synthesize yourTextFieldPicker;
@synthesize textView;

@synthesize postBooking;

-(void) postFirstname:(NSString *)firstname withLastname:(NSString *)lastname withContactno:(NSString *)contactno withEmail:(NSString *)email withClub:(NSString *)club withDatetime:(NSString *)datetime {


if (firstname != nil && lastname != nil && contactno != nil
    && email != nil && club != nil && datetime != nil){

    NSMutableString *postString = [NSMutableString stringWithString:kPostURL];
    [postString appendString:[NSString stringWithFormat:@"?%@=%@", kFirstname, firstname]];        
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kLastname, lastname]];        
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kContactno, contactno]];        
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kEmail, email]];        
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kClub, club]];        
    [postString appendString:[NSString stringWithFormat:@"&%@=%@", kDatetime, datetime]];        
    [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)postBooking:(id)sender{

[self postFirstname: messageTextName.text withLastname: messageTextLastName.text withContactno: messageText.text withEmail: messageTextEmail.text withClub: myPickerLabel.text withDatetime: myDatePickerLabel.text];

[messageTextName resignFirstResponder];

messageTextName.text = nil;
messageTextLastName.text = nil;
messageText.text = nil;
messageTextEmail.text = nil;
myPickerLabel.text = nil;
myDatePickerLabel.text = nil;

[self.navigationController popViewControllerAnimated:YES];

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];

}

- (void)viewDidUnload {

}


- (void)dealloc {

[segmentedControl release];
[myDatePickerLabel release];
[myPickerLabel release];
[myPicker release];
[dataSource release];   
[super dealloc];
[sendMail release]; 
[messageText release];  
[doneEditingButton release];
[fieldsArray release];
[feedbackMsg release];
[tellUsWhatYouThink release];
[messageTextName release];
[messageTextLastName release];
[messageTextEmail release];
[yourTextField release];
[yourTextFieldPicker release];

[postBooking release];

}


@end

PHP ファイル:

<?php 
session_start();
include("connectdb.php");
$first_name = $_GET['messageTextName'];
$last_name = $_GET['messageTextLastName'];
$contactno = $_GET['messageText'];
$email = $_GET['messageTextEmail'];
$club = $_GET['myPickerLabel'];
$date_time = $_GET['myDatePickerLabel'];
$query = "INSERT INTO booking VALUES ('', '$first_name', '$last_name', '$contactno', '$email', '$club', '$date_time')";
mysql_query($query) or die (mysql_error("ERROR"));
mysql_close();
?>
4

1 に答える 1

0

サーバーサイド(PHP)では$_GETグローバル変数を使用していxcodeますが、POSTメソッドを設定しています

[request setHTTPMethod:@"POST"];

phpファイルの変更

$_GET to $_POST or to $_REQUEST.
于 2013-01-21T17:29:12.070 に答える