我正在爲我的客戶端編碼使用以下代碼。它不按我想要的方式工作,也不會將數據保存到遠程服務器。如果我將鏈接直接傳遞給Web瀏覽器,那麼它會將數據保存到遠程數據庫。無法將數據插入遠程數據庫
客戶端:
-(IBAction)Save:(id)sender {
NSString *insrt=[NSString stringWithFormat:@"http://localhost/basInsertv1.php?Zipcode=%i&Locality=%@&Propertytype=%@&pricerange=%@&Bedrooms=%i&Bathrooms=%i&Possession=%@&Propertyage=%@&Rating=%@&Parking=%i&Powerbackup=%i&Security=%i&Swimmingpool=%i",zipcodetf.text.intValue,localitytf.text,proprtytypetf.text,sliderresltlabel.text,bedroomstf.text.intValue,bathrooms.text.intValue,possesiontf.text,propertyAge.text,rating.text,parking.text.intValue,pbu.text.intValue,sec.text.intValue,swim.text.intValue];
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:insrt]];
NSString *r=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",r);
}
服務器端:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'BuyAndSell';
//$dbtable ='bas';
// Connect Database
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die (mysql_error());
mysql_select_db($db, $conn) or die(mysql_error());
if (isset ($_GET['Zipcode']) && isset ($_GET['Locality']) && isset ($_GET['Propertytype']) && isset ($_GET['pricerange']) && isset ($_GET['Bedrooms']) && isset ($_GET['Bathrooms']) && isset ($_GET['Possession']) && isset ($_GET['Propertyage']) && isset ($_GET['Rating']) && isset ($_GET['Parking']) && isset ($_GET['Powerbackup']) && isset ($_GET['Security']) && isset ($_GET['Swimmingpool']))
{
$zipcode=$_GET['Zipcode'];
$locality=$_GET['Locality'];
$propertytype=$_GET['Propertytype'];
$pricerange=$_GET['pricerange'];
$bedrooms=$_GET['Bedrooms'];
$bathrooms=$_GET['Bathrooms'];
$possession=$_GET['Possession'];
$propertyage=$_GET['Propertyage'];
$rating=$_GET['Rating'];
$parking=$_GET['Parking'];
$powerbackup=$_GET['Powerbackup'];
$security=$_GET['Security'];
$swimmingpool=$_GET['Swimmingpool'];
}
else
{
echo "failed";
}
$sql ="INSERT INTO bas(id, zipcode, locality, propertytype,Pricerange,bedrooms,bathrooms,possession,propertyage,rating,parking,powerbackup,security,swimmingpool)VALUES(NULL,'$zipcode','$locality','$propertytype','$pricerange','$bedrooms', '$bathrooms', '$possession', '$propertyage','$rating','$parking','$powerbackup','$security','$swimmingpool');";
$res = mysql_query($sql,$conn) or die(mysql_error());
if ($res)
{
echo "Success";
}
else
{
echo "faild to insert";
}
/* }
else
{
echo "successrr";
}*/
?>
這是印刷failedSuccess
這是正確的。問題出在我的客戶端代碼中。它不會將數據存儲在遠程數據庫上。
好極了!這是工作。但是,你能解釋爲什麼我的代碼不工作嗎? @Vijay Masiwal –