2016-03-21 73 views
1

它是我第一次創建登錄頁面。 我希望用戶登錄,然後頁面重定向到客戶帳戶頁面(如果他們有帳戶)。我添加了回聲,所以我可以看到發生了什麼。我有一個「登錄成功」警報,當我登錄時完美工作。該網頁只是不重定向。PHP-登錄到帳戶工作

HTML

<section class="container"> 
     <form id="myform " class="Form" method="post" action="login.php" accept-charset="utf-8"> 

      <!--     <div id="first">--> 
      <input type="email" id="email" name="email" placeholder="Email Address" value='' required> 
      <input class ="login-field" type="password" id="pass1" name="pass1" value="" placeholder="Password" maxlength="30" required> 
      <input type="submit" name="login" value="login" class="btn "> 
      <br> 
     </form> 

PHP

<?php 
session_start(); 
require ('./mysql.inc.php'); 
?> 

<?php 
     if (isset($_POST['login'])) 

     //database varianbles 
     $c_email = $_POST['email']; 
     $c_password = $_POST['pass1']; 

     // select login details 
     $sel_c = "SELECT * FROM Cus_Register WHERE Cus_Email='$c_email' AND  Cus_Password='$c_password'"; 

     $run_c = mysqli_query($dbc, $sel_c); 
     //check if customer is on databse 
     $check_customer = mysqli_num_rows($run_c); 


     if ($check_customer == 0) { 
      echo "<script> alert('password or email is incorrect please try again')</script>"; 
     exit(); 
     } 
      else{ 
      $_SESSION['Cus_Email'] = $c_email; 
      echo "<script> alert ('Logged in successfully')</script>"; 
      echo "<script>window.open('./customer/Cus_Account.php'.'_self')   </script>"; 
     } 
    ?> 
+0

一開始,你需要因爲你插入不可信數據到您的查詢,而*剝離研究SQLI注射*它 – KDOT

+3

你沒有重定向。你只需要一個彈出窗口,這個窗口可能會被瀏覽器的彈出式殺手殺死。 –

+1

在你的Cus_Account中,確保會話存在也因爲其他人可以直接訪問Cus_Account.php – KDOT

回答

2

你打算window.open('./customer/Cus_Account.php'.'_self')window.open('./customer/Cus_Account.php', '_self')

window.open需要一個位置和目標參數,並且在JavaScript參數中用逗號分隔,而不是句號。在這種情況下,'./customer/Cus_Account.php'是位置,'_self'是目標。

+1

請編輯你的答案,並指定差異,爲什麼它很重要 – CodeGodie

+0

謝謝@Chris,好多了。 – CodeGodie

+1

謝謝你和@CodeGodie這個工作。我不能相信這是一個小錯誤 – jerneva

3

您可以使用header()重定向

else 
{ 
    $_SESSION['Cus_Email'] = $c_email; 
    header('Location: customer/Cus_Account.php'); 
    exit(); 
} 

希望它能幫助:)

+0

謝謝。我現在知道我必須使用標題。但它仍然不起作用 – jerneva