Ich muss meine App registrieren. Ich speichere Daten in mysql. Ich versuche eine Lösung, aber es funktioniert nicht. Wenn Sie irgendeine Lösung haben, bitte helfen Sie mir wissen! Ich speichere meine Daten zu meiner SQL durch URL:IOS-Wie speichere ich Daten mit mysql?
Hier ist meine Funktion speichern Daten:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UITapGestureRecognizer *oneTapGesture = [[UITapGestureRecognizer alloc]
initWithTarget: self
action: @selector(hideKeyboard:)];
[oneTapGesture setNumberOfTouchesRequired:1];
[[self view] addGestureRecognizer:oneTapGesture];
}
-
(IBAction)btnSave:(id)sender {
Pheptoan *functionStr = [[Pheptoan alloc] init];
NSInteger success=0;
@try{
if([[self.txtUsername text] isEqualToString:@""] || [[self.txtPassword text] isEqualToString:@""] || [[self.txtEmail text] isEqualToString:@""]
|| [[self.txtName text] isEqualToString:@""]|| [[self.txtTel text] isEqualToString:@""]){
[self showUIAlertWithMessage:@"User/Email not blank \n Password not blank" andTitle: @"Message"];
}else{
NSString *password = _txtPassword.text;
NSData *passwordData = [password dataUsingEncoding:NSUTF8StringEncoding];
NSString *passwordMD5 = [functionStr MD5:passwordData];
NSString *userUrl = [NSString stringWithFormat:@"http://ios.khothe.vn/web/gamecard/register/sUsername/%@/sPassword/%@/sName/%@/sEmail/%@/sTel/%@", _txtUsername.text, passwordMD5,_txtName.text,_txtEmail.text,_txtTel.text];
NSLog(@"link: %@", userUrl);
NSURL *url = [NSURL URLWithString:userUrl];
NSURLRequest *request=[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30.0];
NSError *error = nil;
NSHTTPURLResponse *response;
NSData *data= [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (!data) {
NSLog(@"Error: %@", [error localizedDescription]);
}
if([response statusCode]>=200 && [response statusCode]<300){
NSError *error= nil;
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
success = [[jsonDictionary valueForKey:@"success"] integerValue];
if(success == 400){
[self showUIAlertWithMessage:@"sucessfull" andTitle:@"Message"];
}else{
[self showUIAlertWithMessage:@"Error! Please wrong username or password" andTitle:@"Message"];
}
}
}
}@catch(NSException *e){
[self showUIAlertWithMessage:@"Error! Please login again" andTitle:@"Message"];
}
if(success == 400){
[self performSegueWithIdentifier:@"loginSuccess" sender:self];
}
}
Hier ist meine Funktion Daten in mysql speichern ist:
public function actionRegister()
{
$connection = Yii::app()->dbgamecard;
if($_GET != null){
$sUsername = $_GET["sUsername"];
$sPassword = $_GET["sPassword"];
$sName = $_GET["sName"];
$sEmail = $_GET["sEmail"];
$sTel = $_GET["sTel"];
$userInfo = Yii::app()->dbgamecard->createCommand("SELECT Username FROM member WHERE Username=:sUsername")
->bindParam(':sUsername', $sUsername)
->queryRow();
$arr = null;
if($userInfo){
echo json_encode(array("success" => 404));
//$arr["Status"] = "0";
//$arr["Message"] = "Username Exists!";
//echo json_encode($arr);
exit();
}
$userInfo = Yii::app()->dbgamecard->createCommand("SELECT Email FROM member WHERE Email=:sEmail")
->bindParam(':sEmail', $sEmail)
->queryRow();
if($userInfo){
echo json_encode(array("success" => 404));
//$arr["Status"] = "0";
//$arr["Message"] = "Email Exists!";
//echo json_encode($arr);
exit();
}
$strSQL = "INSERT INTO member (Username,Password,Name,Email,Tel)
VALUES(:strUsername, :strPassword, :strName, :strEmail, :strTel)";
$command= $connection->createCommand($strSQL);
$command->bindParam(":strUsername", $sUsername,PDO::PARAM_STR);
$command->bindParam(":strPassword", $sPassword,PDO::PARAM_STR);
$command->bindParam(":strName", $sName,PDO::PARAM_STR);
$command->bindParam(":strEmail", $sEmail,PDO::PARAM_STR);
$command->bindParam(":strTel", $sTel,PDO::PARAM_STR);
$command->execute();
if(!$command)
{
echo json_encode(array("success" => 404));
//$arr["Status"] = "0";
//$arr["Message"] = "Cannot Save Data!";
//echo json_encode($arr);
exit();
}
else{
$userInfo1['success'] = 400;
echo json_encode($userInfo);
//$arr["Status"] = "1";
//$arr["Message"] = "Register Successfully!";
//echo json_encode($arr);
exit();
}
}
mysql_close($objConnect);
}
}
Und Fehler, den ich bekommen
2016-05-19 17:17:19.738 gamecard App[1608:126645] -[RegisterController hideKeyboard:]: unrecognized selector sent to instance 0x7fdbbb645560
2016-05-19 17:17:19.742 gamecard App[1608:126645] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RegisterController hideKeyboard:]: unrecognized selector sent to instance 0x7fdbbb645560'
*** First throw call stack:
(
0 CoreFoundation 0x0000000103164d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010284fdeb objc_exception_throw + 48
2 CoreFoundation 0x000000010316dd3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001030b3cfa ___forwarding___ + 970
4 CoreFoundation 0x00000001030b38a8 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001045c6b28 _UIGestureRecognizerSendTargetActions + 153
6 UIKit 0x00000001045c319a _UIGestureRecognizerSendActions + 162
7 UIKit 0x00000001045c1197 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 843
8 UIKit 0x00000001045c9655 ___UIGestureRecognizerUpdate_block_invoke898 + 79
9 UIKit 0x00000001045c94f3 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 342
10 UIKit 0x00000001045b6e75 _UIGestureRecognizerUpdate + 2634
11 UIKit 0x000000010414348e -[UIWindow _sendGesturesForEvent:] + 1137
12 UIKit 0x00000001041446c4 -[UIWindow sendEvent:] + 849
13 UIKit 0x00000001040efdc6 -[UIApplication sendEvent:] + 263
14 UIKit 0x00000001040c9553 _UIApplicationHandleEventQueue + 6660
15 CoreFoundation 0x000000010308a301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 CoreFoundation 0x000000010308022c __CFRunLoopDoSources0 + 556
17 CoreFoundation 0x000000010307f6e3 __CFRunLoopRun + 867
18 CoreFoundation 0x000000010307f0f8 CFRunLoopRunSpecific + 488
19 GraphicsServices 0x0000000107ae5ad2 GSEventRunModal + 161
20 UIKit 0x00000001040cef09 UIApplicationMain + 171
21 gamecard App 0x00000001022bda9f main + 111
22 libdyld.dylib 0x000000010626192d start + 1
23 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Ich bin nicht sicher, dass mein Code gute Arbeit ist. Aber wenn Sie eine Lösung über das Speichern von Daten in MySQL haben, lassen Sie es mich bitte wissen. Ich schätze jede Unterstützung. Danke!
Sie müssen verbergenKeyboard-Methode in RegisterController implementieren – azimov