the problem i am face right now is i can’t pass a variable from iphone to php page.First i want to pass the country name to php page from iphone.
This is the php code:
$coname=$_POST["c_name"];
$con = mysql_connect("url","username","password");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("Appiness", $con);
header("Content-Type: text/xml");
$bilgi= mysql_query("SELECT age,wname,slid,sex FROM user WHERE user.c_name='".$coname."'");
while($sutun= mysql_fetch_array($bilgi))
{
echo $sutun["age"];
echo $sutun["wname"];
echo $sutun["sex"];
echo $sutun["slid"];
}
mysql_close($con);
this is the part i ‘ve call the php page in xcode
NSString *country=[[NSUserDefaults standardUserDefaults]objectForKey:@"namecountry"];
//url's
NSURL *url = [NSURL URLWithString:@"http://www.trevesstudios.com/get.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:country forKey:@"c_name"];
[request setRequestMethod:@"POST"];
[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request startSynchronous];
response = [request responseString];
NSLog(@"%@",response);
Can anyone help me for why this code is not working btw when i try to change the WHERE c_name=’France’ it works the the problem is the variable.Can anybody helpme?
A few things to check:
what is
countryvalue after reading it fromNSUserDefaults?what does
NSLog(@"%@",response);print out?in your PHP, what is
$coname?is
$_POSTdefined? is$_GETdefined? could you print out$_REQUESTcontent (print_r($_REQUEST))?EDIT:
can you put this statement
before
$coname=$_POST["c_name"];?can you add this statement:
after executing
mysql_query?what does it output?
EDIT2:
With the
echoes we added above, we now know that the post parameter is arriving at the server. Are you sure that there are data stored for France in your database? mysql_error did not return any error (0: in the output), so everything went ok… it seems that the query returned no data, but it did not fail…Anyway, just as a further check, could you add this more statement before executing mysql_query?
so we will see what the query looks like…
EDIT3:
please, replace:
by
EDIT 4: