2011-12-13 35 views
0

我試圖通過PHP中使用MySQL創建爲iPad登錄頁面,但它不是在即使是在網頁沒有錯誤記錄,請看下面的代碼:使用PHP for iPhone創建登錄頁面?

//-(IBAction)homePage: (id)sender{ 

NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",loginName.text, password.text]; 

NSString *hostStr = @"http://localhost/iddb.php"; 
hostStr = [hostStr stringByAppendingString:post]; 
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];  
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding]; 
if([serverOutput isEqualToString:@"Yes"]){{ 


    homepage *hvc = [[homepage alloc]initWithNibName: nil bundle: nil]; 
    hvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:hvc animated: YES];} 

    UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"success" message:@"You are authorized" 
                  delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; 
    [alertsuccess show]; 


} else { 
    UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Fail" message:@"Invalid Access" 
                  delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; 
    [alertsuccess show]; 


} 

PHP代碼:

<?php 
    $username = $_GET['username']; 
    $password = $_GET['password']; 
    $check = "select username, password from login where username='$username' and password='$password'"; 
    { 
     mysql_connect("localhost", "root","") or die(); 
     mysql_select_db("dadsdb") or die (mysql_error()); 
    } 

    $login = mysql_query($check) or die (mysql_error()); 

    if (mysql_num_rows($login)==1) { 
     $row = mysql_fetch_assoc($login); 
     echo 'yes'; 
     exit; 
    } else { 
     echo 'No'; 
     exit; 
    } 
?> 

請任何人可以建議我什麼地方出了錯

+0

請編輯您的帖子並在其中添加PHP代碼。 –

+3

該PHP代碼使我的頭髮站起來.... –

+0

我從評論複製php代碼到問題的身體。我也相應地縮進了它。應該很明顯,提供的代碼有語法錯誤,因爲{和}大括號不應該是。 –

回答

2

使用情況下sensitve結果!

'yes' != 'Yes' 
+0

就在那裏,那麼微妙!好找! –

0

在你的URL中,你不是將你的php與參數分開嗎?

NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",loginName.text, password.text]; 
NSString *hostStr = @"http://localhost/iddb.php"; 
hostStr = [hostStr stringByAppendingString:post]; 

這將結束與

http://localhost/iddb.phpusername= .... 而你應該有 http://localhost/iddb.php?username= ....

無論其...這是你有問題,許多事情之一在你的代碼中。請注意人們給你的評論和其他答案 - *你需要檢查你的大小寫。
*閱讀了有關SQL注入 *請勿數據庫 上使用root身份登錄*請勿數據庫 上使用root沒有密碼*請勿明文 密碼儲存*不要在任何發送密碼以明文連接(例如,在你的URL)

你必須與你的PHP代碼一些非常嚴重的問題,這可能導致有人登錄不合法的用戶名和密碼,能夠訪問所有的數據或更糟的。