So I wrote the PHP to check an inputed username against the MySQL database. I can send a request with the username from the iPhone to the PHP fine. The problem is getting something back.
How do I return just a boolean from the PHP code to the objective-c code?
I have this sending the username:
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://nailorbail.net63.net/submit_user_info.php?username=%@",username]]];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
And this on the PHP side:
$username = mysql_real_escape_string($_GET['username']);
$usernameArray = array();
$query = "SELECT username FROM main;";
$result = mysql_query($query);
$max = 0;
while($row = mysql_fetch_assoc($result)) {
$usernameArray[$max] = $row['username'];
$max++;
}
for ($i = 0; $i < $max; $i++)
{
if (strcasecmp($username, $usernameArray[$i]) == 0)
{
echo $username . ' is equal to ' . $usernameArray[$i];
break;
}
}
When I access the page manually in my browser making a value from username
it works perfectly.