2014-04-09 2 views
0

내 로그인은 작동하지만 DB에서 사용자 이름을 반향하려고 시도하면 오류가 발생합니다. "구문 분석 오류 : 예기치 않은 $ end of /home/..../public_html/app/views 내 코드 "라인 (31)에 /login/logout.php :로그인이 작동하지 않음

<?php 
    session_start(); 

    if (isset($_POST['username']) and isset($_POST['password'])){ 
    //3.1.1 Assigning posted values to variables. 
    $username = $_POST['username']; 
    $password = $_POST['password']; 

    $query = "SELECT * FROM `loginuser` WHERE username='$username' and password='$password'"; 

    $result = mysql_query($query) or die(mysql_error()); 
    $count = mysql_num_rows($result); 
    //3.1.2 If the posted values are equal to the database values, then session will be created for the user. 
    if ($count == 1){ 
    $_SESSION['username'] = $username; 
    }else{ 
    //3.1.3 If the login credentials doesn't match, he will be shown with an error message. 
    echo "Invalid Login Credentials."; 
    } 
    } 

    if (isset($_SESSION['username'])){ 
    $username = $_SESSION['username']; 
    echo "Hello " . $username . ""; 
    echo "This is the Members Area"; 
    echo "<a href='logout'>Logout</a>"; 
    }else{ 


    ?> 
+6

** 일반 텍스트로 비밀번호를 저장하지 마십시오 ** –

+0

else 문에 대괄호가 없습니다. –

+2

'else {'---'''를 추가하거나 제거하십시오. –

답변

3

당신은 마지막에 당신의 else}를 추가해야합니다. 사용 중이 지 않으므로 삭제하십시오.

}else{ 
} 
?> 
1
<?php 
session_start(); 

if (isset($_POST['username']) and isset($_POST['password'])){ 
//3.1.1 Assigning posted values to variables. 
$username = $_POST['username']; 
$password = $_POST['password']; 

$query = "SELECT * FROM `loginuser` WHERE username='$username' and password='$password'"; 

$result = mysql_query($query) or die(mysql_error()); 
$count = mysql_num_rows($result); 
//3.1.2 If the posted values are equal to the database values, then session will be created for the user. 
if ($count == 1){ 
$_SESSION['username'] = $username; 
}else{ 
//3.1.3 If the login credentials doesn't match, he will be shown with an error message. 
echo "Invalid Login Credentials."; 
} 
} 

if (isset($_SESSION['username'])){ 
$username = $_SESSION['username']; 
echo "Hello " . $username . ""; 
echo "This is the Members Area"; 
echo "<a href='logout'>Logout</a>"; 
}else{ 
    // Do nothing 
} 
?> 

또는 완전히 다른 마지막 생략합니다.

관련 문제