2013-03-09 82 views
0

嗨即時嘗試找到一種方法爲我的登錄腳本添加if語句,以便它檢查我的數據庫,以查看列'close_accounut'='1',然後顯示此錯誤消息。在登錄時創建if語句?

} else { 
        $closed_set = closed_account(); 
while ($closed = mysql_fetch_array($closed_set)) 
      if ($closed['close_account'] == '1') { 
       $message = "<div class=\"infobox_out\">This account is closed. You recently closed your account. To regain access please email <a href=\"mailto:[email protected]\">[email protected]</a> session has expired.</div>"; 
      echo "<a href=\"#\"><div class=\"infobox-close2\"></div></a>"; 

否則如果close_account = '0',則顯示正常的錯誤消息;

// email/password combo was not found in the database 
       $message = "<div class=\"infobox_out\"><strong>Email/Password combination incorrect.</strong><br /> 
        Please make sure your caps lock key is off and try again.</div>"; 
        echo "<a href=\"#\"><div class=\"infobox-close2\"></div></a>"; 

我曾嘗試以下,但是這只是什麼都不做,請能有人告訴我,我要去哪裏錯了感謝

<?php 

    if (logged_in()) 

{ 
$_SESSION['login_message']="<div class=\"login-overlay\"></div><div class=\"login-box\"><div class=\"loginframe2\"> 
<h1>Login You In Securely </h1> 
<p>login you in securely. Please wait.<br/><br/> 
<div class=\"login-logo\"> 
    <img src=\"assets/css/photobox/loading.gif\" width=\"24\" height=\"24\"><div class=\"login-text-logo\">Login You In. Please Wait</div></div> 
</div></div>"; 
header("Location:home.php"); 


} 

    include_once("includes/form_functions.php"); 


    // START FORM PROCESSING 
    if (isset($_POST['submit'])) { // Form has been submitted. 
     $errors = array(); 

     // perform validations on the form data 
     $required_fields = array('email', 'password'); 
     $errors = array_merge($errors, check_required_fields($required_fields, $_POST)); 

     $fields_with_lengths = array('email' => 50, 'password' => 30); 
     $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST)); 

     $email = trim(mysql_prep($_POST['email'])); 
     $password = trim(mysql_prep($_POST['password'])); 
     $hashed_password = md5($password); 


     if (empty($errors)) { 
      // Check database to see if email and the hashed password exist there. 
      $query = "SELECT id, email, close_account "; 
      $query .= "FROM ptb_users "; 
      $query .= "WHERE email = '{$email}' "; 
      $query .= "AND password = '{$hashed_password}' "; 
      $query .= "AND close_account = '0' "; 
      $query .= "LIMIT 1"; 
      $result_set = mysql_query($query); 
      confirm_query($result_set); 
      if (mysql_num_rows($result_set) == 1) { 
       // email/password authenticated 
       // and only 1 match 
       $found_user = mysql_fetch_array($result_set); 
       $_SESSION['user_id'] = $found_user['id']; 
       $_SESSION['email'] = $found_user['email']; 
       $_SESSION['sub_expires'] = $found_user['subscription_expires']; 





       $result = mysql_query("UPDATE ptb_users SET user_online='Online' WHERE id=".$_SESSION['user_id']."") 
or die(mysql_error()); 

if($result) 
{ 
$_SESSION['login_message']="<div class=\"login-overlay\"></div><div class=\"login-box\"><div class=\"loginframe2\"> 
<h1>Login You In Securely </h1> 
<p> PlaytimeBoys.com is login you in securely. Please wait.<br/><br/> 
<div class=\"login-logo\"> 
    <img src=\"assets/css/photobox/loading.gif\" width=\"24\" height=\"24\"><div class=\"login-text-logo\">Login You In. Please Wait</div></div> 
</div></div>"; 
header("Location:home.php"); 

} 


      }else{ 

       // email/password combo was not found in the database 
       $message = "<div class=\"infobox_out\"><strong>Email/Password combination incorrect.</strong><br /> 
        Please make sure your caps lock key is off and try again.</div>"; 
        echo "<a href=\"#\"><div class=\"infobox-close2\"></div></a>"; 

      } 

       } else { 
        $closed_set = closed_account(); 
while ($closed = mysql_fetch_array($closed_set)) 
      if ($closed['close_account'] == '1') { 
       $message = "<div class=\"infobox_out\">This account is closed. You recently closed your account. To regain access please email <a href=\"mailto:[email protected]\">[email protected]</a> session has expired.</div>"; 
      echo "<a href=\"#\"><div class=\"infobox-close2\"></div></a>"; 
+1

有了這個縮進亂七八糟很難看,但它看起來像你的塊不正確作用域(即'{'和'}'那環繞塊的順序是不可能你想要什麼)。我建議你先清理你的代碼,然後檢查你的代碼是否遵循'if(...){..} else {..}'模式。 – fvu 2013-03-09 14:09:47

回答

0

我想你錯過了一個「{」的一段時間。改變你的波紋管:

} else { 
        $closed_set = closed_account(); 
while ($closed = mysql_fetch_array($closed_set)) 
{ 
      if ($closed['close_account'] == '1') { 
       $message = "<div class=\"infobox_out\">This account is closed. You recently closed your account. To regain access please email <a href=\"mailto:[email protected]\">[email protected]</a> session has expired.</div>"; 
      echo "<a href=\"#\"><div class=\"infobox-close2\"></div></a>";