2014-11-05 105 views
0

我想知道我錯過了哪些錯誤。與會話登錄表單錯誤

我的形式會是這樣

<form id="myForm" action="loginAction" name="login" method="POST"> 
     <p> <label class="inputField" > Email Address : </label> </p> 
     <p> <input class="registerField" id="emailid" name="email" required="required" type="text" placeholder="eg. [email protected]"/> <span class="warning" id="emailWarning"> </p> 

     <p> <label class="inputField" > Password : </label> </p> 
     <p> <input class="registerField" id="textpwd" name="password" required="required" type="password" placeholder="Your password"/> </p> 

    <p> <input name="submit" class="registerButton" type="submit" value="LOGIN"> </p> 

loginAction.php低於

<?php 
// Report all PHP errors 
error_reporting(-1); 

session_start(); 

include 'dbconnect.php'; 

$username = $_POST['email']; 
$password = $_POST['password']; 

$username = mysqli_real_escape_string(stripslashes($username)); 
$password = mysqli_real_escape_string(stripslashes($password)); 

$loginUser = " SELECT registerPassword, emailAddress FROM register_user 
       WHERE emailAddress = '$username' AND registerPassword = '$password'"; 
$loginSuccess = mysqli_query($mysqli, $loginUser) or die(mysqli_error($mysqli)); 
$loginRow = mysqli_num_rows($loginSuccess); 

if($loginRow == 1) { 
    // $_SESSION['login_user'] = $username; 
    echo "SUCCESSFUL LOGIN"; 
    //header ("Location: index"); 
    } else { 
     echo "YOU WRONG"; 
    } 
mysqli_close($mysqli); 

?>

答案是你錯了即使密碼和下面的代碼電子郵件是一樣的。我知道我還沒有完成會議,但這不能登錄,所以我不能做更多的會話。

+0

你進入你的分貝相同的憑據? – Tushar 2014-11-05 09:25:37

+0

是的,我認爲它是@TusharGupta – Anthosiast 2014-11-05 09:27:01

+0

首先將php代碼放在一個'if(isset($ _ POST ['submit'])){}'中,以確保表單正常工作,然後打印出你得到的表單數據庫和什麼值依賴'$ loginRow' ... – 2014-11-05 09:27:56

回答

1

你形成字段名電子郵件沒有username變化

$username = $_POST['username']; 

$username = $_POST['email']; 

而且錯誤報告和

打開PHP標籤像<?php session_start();

+0

沒有注意到,謝謝btw ..仍然沒有記錄在.. – Anthosiast 2014-11-05 09:22:39

+0

嘗試error_reporting(1); – 2014-11-05 09:25:05

+0

嘗試用我更新的答案 – 2014-11-05 09:26:45

0
之前刪除空格

您在loginAction.php

因爲在你把表格 $username = $_POST['username'];

改變它$username = $_POST['email'];

你寫:

<input id="emailid" name="email" type="text"/>

if($loginRow!=0) { 
    // $_SESSION['login_user'] = $username; 
    echo "SUCCESSFUL LOGIN"; 
    //header ("Location: index"); 
    } else { 
     echo "YOU WRONG"; 
    } 
+0

如果你要檢查下面的用戶說了什麼,你會看到它不起作用仍然 – 2014-11-05 09:28:47

+0

第二件事可能實際上工作;) – 2014-11-05 09:30:37

+0

它不工作你 – Anthosiast 2014-11-05 09:50:46