得到错误的int值,我通过一个iOS应用程序,检查进入UITextFields细节,并允许用户登录运行我的服务器上的PHP脚本。Th反应回简直是从字符串
<?php require_once("includes/connection_auth.php");
?>
<?php
$username = $_GET["userName"];
$userpassword = $_GET["userPassword"];
//check if users username exists in database
$selectQuery = mysqli_query($connection, "SELECT * FROM MVUsers WHERE userName = '$username' ");
if (!$selectQuery) {
printf("Error: %s\n", mysqli_error($connection));
exit();
}
if ($row = mysqli_fetch_assoc($selectQuery)){
//user found in database check password matches
if($row ['userPassword'] == $userpassword){
//password matches check if confirmed email
if($row ['userHasConfirmedEmail'] == 1){
//allow user to log in
echo (0);
}
else{
echo (1);
}
}
else{
//password does not match warn user
echo (2);
}
}
else{
echo(3);
}
//close connection to database
mysqli_close($connection);
?>
这个回显的数字作为NSData返回到我的应用程序,并在NSURLConnectionDataDelegate回调之一,我将该数据转换为NSString然后从该字符串中获取intValue。
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *string = [[NSString alloc]initWithData:[self receivedData] encoding:NSUTF8StringEncoding];
NSLog(@"Connection finished loading with string :%@",string);
int returnedInt = [string intValue];
NSLog(@"%i",returnedInt);
// returnedInt is the compared inside a switch statement.
}
这两个日志语句对于相同的数据具有不同的输出。
2014-02-05 13:20:47.363 MotoVlogger[50944:70b] Connection finished loading with string :
3
2014-02-05 13:20:47.363 MotoVlogger[50944:70b] 0
为什么3是在一个实例中,0在另一个为什么所有在第一个日志语句中添加空白的所有?
您的php无效。 – njzk2
对不起我sudo编码我会更新与实际的PHP。这将改变我原来的帖子 – RyanTCB
你也可以删除“mysql”标签。这似乎与数据库无关。 –