2015-05-05 114 views
0
<form action='login.php' method='POST'> 
    Username: <input type='text' name='Username'><BR> 
    Password: <input type='password' name='Password'><BR> 
    <input type="checkbox" name="remember" > Rember Me 
    <input type='submit' value='Log in'> 
    <a href="reg.php"> Register </a> 

<?php 
session_start(); 
include 'db.php'; 

$Username = $_POST['Username']; 
$Password = $_POST['Password']; 

if ($Username&&$Password) 
{ 
$query = mysql_query("SELECT * From Users WHERE Username='$Username'"); 

$numrow = mysql_num_rows($query); 

if ($numrow!=0) 

{ 
    while ($row = mysql_fetch_assoc($query)) 
    { 
     $Username = $row['Username']; 
     $Password = $row['Password']; 
    } 

    // check to see if they match 
    if ($Username==$Username&&$Password==$Password) 
    { 
     echo "You're in. <a href='index.php'>Click</a> here to enter the member page"; 
     $_SESSION['Username']=$Username; 
    } 

    else 
     echo "Incorrect password"; 
} 
else 
    die("That user doesn't exist"); 

} 
else 
    die ("please enter a username and a password"); 

?> 

誤差即時得到是:說明:未定義指數誤差

說明: 未定義指數:用戶名在/home/stud/0/1314683/public_html/MathsrUs/login.php在線路48上的通知:未定義指數:密碼在/home/stud/0/1314683/public_html/MathsrUs/login.php在線49

+0

您的代碼在一個文件或兩個單獨的文件中。另外你的文件操作是一些東西,但你的按鈕是一個鏈接正在把你帶到別的地方? –

+0

都在與html和php相同的名爲login.php的文件中。 –

回答

0

有一個在$ _ POST

$Username = $_POST['Username']; 

$Password = $_POST['Password']; 

檢查沒有數據,如果頁面獲得通過POST訪問,你可以ch eck如果用$ _SERVER ['REQUEST_METHOD']變量。

+0

當我把該代碼。我得到解析錯誤:語法錯誤,意想不到的T_VARIABLE在49行上的/home/stud/0/1314683/public_html/MathsrUs/login.php –

+0

只需檢查這個 -

用戶名:
密碼:
Rember Me Register <?php session_start(); 包含'db.php';如果(isset($ _ POST)&&!empty($ _ POST)){ $ Username = $ _POST ['Username']; $ Password = $ _POST ['Password']; print_r($ _ POST); die; }。我刪除了所有其他代碼,只是爲了您的理解目的,即您誤認爲是錯誤的。輸出截圖: - http://prntscr.com/722t7r –