1
首先,我需要說我是iPhone開發新手,所以請我需要你具體!iPhone和MySQL
我正在爲學校的科學項目開發一個應用程序,問題是:如何從iPhone上的UITextFields將數據插入到MySQL表中?
在我的應用程序中,我有3個UITextFields,所以我需要將這些UITextFields值插入到mysql表中。你知道這麼做並不重要,我很匆忙,我只是想把它付諸實施。
1 - 我與這個PHP代碼
<?php
if (isset ($_GET["matricula"]))
$matricula = $_GET["matricula"];
else
$matricula = "ELO";
$sql="INSERT INTO chatitems (user, message, matricula) VALUES ('$_GET[user]','$_GET[messages]','$_GET[matricula]')";
$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error());
mysql_select_db($DB_Name,$con) or die(mysql_error());
//$sql = "insert into $DB_Table (matricula) values('$matricula');";
$res = mysql_query($sql,$con) or die(mysql_error());
mysql_close($con);
if ($res) {
echo "success";
}else{
echo "faild";
}// end else
?>
工作,我插入此代碼在我的應用程序(的Xcode 4.1)
- (IBAction)insert:(id)sender
{
// create string contains url address for php file, the file name is phpFile.php, it receives parameter :name
NSString *strURL = [NSString stringWithFormat:@"http://localhost:8888/phpFile.php?name=%@",txtName.text];
//NSString *strURL = [NSString stringWithFormat:@"http://localhost:8888/phpFile.php?name=%@",txtMatricula.text];
// to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
// to receive the returend value
NSString *strResult = [[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]autorelease];
NSLog(@"%@", strResult);
NSString *cont11 = [NSString stringWithFormat:@"http://localhost:8888/UEUO/insertMT.php?name=%@",txtName.text];
NSString *cont21 = [NSString stringWithFormat:@"http://localhost:8888/UEUO/insertMT.php?matricula=%@",txtMatricula.text];
NSData *cont12 = [NSData dataWithContentsOfURL:[NSURL URLWithString:cont11]];
NSData *cont22 = [NSData dataWithContentsOfURL:[NSURL URLWithString:cont21]];
NSString *cont13 = [[[NSString alloc] initWithData:cont12 encoding:NSUTF8StringEncoding]autorelease];
NSLog(@"%@", cont13);
NSString *cont23 = [[[NSString alloc] initWithData:cont22 encoding:NSUTF8StringEncoding]autorelease];
NSLog(@"%@", cont23);
}
此代碼工作正常,只有一個UItextField
,我需要three3。
重複:如何使用PHP和C++將三個UITextFields的值插入到MySql表中?
如果您知道如何幫助我,或者向我發送一個教程或一段代碼,請一切有用!
這麼多感謝的人對我來說非常完美!你是那個傢伙。儘快我會假裝發佈我的教程解釋這個以幫助其他人!非常感謝你拯救了我的生命!祝賀你是我的人! –
+1尋找相同的:)! – iUser