Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > iOS xcode เชื่อมต่อกับ MySQL localhost ผ่าน XMAPP ไม่ได้คะ



 

iOS xcode เชื่อมต่อกับ MySQL localhost ผ่าน XMAPP ไม่ได้คะ

 



Topic : 107485



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์




ทำ Xcode ตามกระทู้นี้คะ https://www.thaicreate.com/mobile/ios-iphone-add-insert-data-to-web-server.html

แต่ว่าทำตามแล้วขึ้น
ERROR แบบนี้คะ ข้อมูลไม่ถูกใส่เข้าไปใน Database คะ

ERROR

รูป MySQL คะ

XAMPP

>>>โค้ดของไฟล์ saveData.php คะ

Code
<?
	/*** for Sample 
		$_POST["sName"] = "a";
		$_POST["sTel"] = "b";
	*/

	$strName = $_POST["sName"];
	$strTel = $_POST["sTel"];

	$objConnect = mysql_connect("localhost","root","root");
	$objDB = mysql_select_db("UserSupport");

	/*** Insert ***/
	$strSQL = "INSERT INTO member (Name,Tel) 
		VALUES (
			'".$strName."',
			'".$strTel."'
			)
		";
	echo "sName";
	
	$objQuery = mysql_query($strSQL);

	$arr = null;
	if(!$objQuery)
	{
		$arr["Status"] = "0";
		$arr["Message"] = "Insert Data Failed";
	}
	else
	{
		$arr["Status"] = "1";
		$arr["Message"] = "Insert Data Successfully";
	}
	
	echo json_encode($arr);
?>


>>>อันนี้โค้ดใน xCode ViewController.m คะ

Code
- (IBAction)btnSave:(id)sender {
    //Name=Poo&Tel=023456789"
    NSMutableString *post = [NSMutableString stringWithFormat:@"sName=%@&sTel=%@",[txtName text],[txtTEl text]];
    
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    
    NSURL *url = [NSURL URLWithString:@"http://localhost/saveData.php"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
                                                           cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                                       timeoutInterval:10.0];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
	[request setHTTPBody:postData];
    
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
    
    
    // Show Progress Loading...
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
    loading = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [loading addSubview:progress];
    [progress startAnimating];
  //  [progress release];
    [loading show];
    
    if (theConnection) {
        self.receivedData = [NSMutableData data];
    } else {
		UIAlertView *connectFailMessage = [[UIAlertView alloc] initWithTitle:@"NSURLConnection " message:@"Failed in viewDidLoad"  delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
		[connectFailMessage show];
	//	[connectFailMessage release];
    }
    
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    sleep(5);
    [receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    
//    [connection release];
//    [receivedData release];
    
    // inform the user
    UIAlertView *didFailWithErrorMessage = [[UIAlertView alloc] initWithTitle: @"NSURLConnection " message: @"didFailWithError"  delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
    [didFailWithErrorMessage show];
    //[didFailWithErrorMessage release];
	
    //inform the user
    NSLog(@"Connection failed! Error - %@", [error localizedDescription]);
    
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // Hide Progress
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
    [loading dismissWithClickedButtonIndex:0 animated:YES];
    
    // Return Status E.g : { "Status":"1", "Message":"Insert Data Successfully" }
    // 0 = Error
    // 1 = Completed
    
    if(receivedData)
    {
        //NSLog(@"%@",receivedData);
        
        //NSString *dataString = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding];
        //NSLog(@"%@",dataString);
        
        id jsonObjects = [NSJSONSerialization JSONObjectWithData:receivedData options:NSJSONReadingMutableContainers error:nil];
        
        // value in key name
        NSString *strStatus = [jsonObjects objectForKey:@"Status"];
        NSString *strMessage = [jsonObjects objectForKey:@"Message"];
        NSLog(@"Status = %@",strStatus);
        NSLog(@"Message = %@",strMessage);
        
        // Completed
        if( [strStatus isEqualToString:@"1"] ){
            UIAlertView *completed =[[UIAlertView alloc]
                                     initWithTitle:@": -) Completed!"
                                     message:strMessage delegate:self
                                     cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [completed show];
        }
        else // Error
        {
            UIAlertView *error =[[UIAlertView alloc]
                                 initWithTitle:@": ( Error!"
                                 message:strMessage delegate:self
                                 cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [error show];
        }
        
    }
    
    // release the connection, and the data object
//    [connection release];
//    [receivedData release];

}



รบกวนแนะนำหนูหน่อยค่า
ขอบคุณค่ะ ^^



Tag : Mobile, MySQL, iOS, Objective-C, Mobile







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-04-04 17:25:51 By : gift9590 View : 2519 Reply : 10
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
http://localhost/saveData.php


URL นี้ใช้ได้จริงหรือเปล่าครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-05 20:30:59 By : mr.win
 


 

No. 2



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


link

พอเอาลิ้งไปวางช่อง address ก็ขึ้นตามรูปเลยคะ

หนูเอาไฟล์ savedata.php ไปไว้ใน Application > Xampp > htdocs คะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-07 17:58:00 By : gift9590
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Error นี้มีวิธีแก้ไขเยอะครับ ค้นหาได้ในกระทู้เก่า ๆ ครับ (คือตอนนี้จะต้องแก้ไขบน php ให้มัน Save ได้ปกติก่อนครับ)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-07 18:22:10 By : mr.win
 


 

No. 4



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


ตอนนี้เหลือ อันนี้คะ
Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in /Applications/XAMPP/xamppfiles/htdocs/saveData.php on line 9
{"Status":"0","Message":"Insert Data Failed"}

หนูไปเช็ค User กับ Pass ใน phpmyadmin แล้วก็เป็น root root
ตามที่เขียนในโค้ดแล้วอะคะ
root

พอมีวิธีแก้ไขอีกไหมคะ รบกวนด้วยค่าาา T---T
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-07 19:16:17 By : gift9590
 


 

No. 5



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


ใน line 9 เป็นคำสั่งนี้ค่ะ YY
Code
$objConnect = mysql_connect("localhost","root","root");

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-07 19:18:50 By : gift9590
 


 

No. 6



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์


ยังแก้ไขไม่ได้เลยค่ะ T----T
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-22 23:53:41 By : gift9590
 


 

No. 7



โพสกระทู้ ( 830 )
บทความ ( 0 )



สถานะออฟไลน์


Code
Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in /Applications/XAMPP/xamppfiles/htdocs/saveData.php on line 9
{"Status":"0","Message":"Insert Data Failed"}



มันแจ้งว่า User name หรือ Password ผิดนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-26 07:02:33 By : danya
 


 

No. 8



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

แก้ไข Connection ของ PHP กับ MySQL ให้ถูกก็ได้แล้วครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-26 08:22:53 By : mr.win
 


 

No. 9

Guest


ติดเหมือนกันเลย แก้ยังไงก็ไม่ออกสักกะที
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-09-20 13:12:35 By : แบงค์
 


 

No. 10

Guest


xcode ในxcodeมันขึ้นแบบนี้อ่ะคับ พอเวลารันแล้วมันไม่เชื่อมให้อ่ะคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-09-20 13:16:27 By : แบงค์
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : iOS xcode เชื่อมต่อกับ MySQL localhost ผ่าน XMAPP ไม่ได้คะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่