2012-03-22 311 views
-1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Login</title> 
<style> 
    label{ 
     width:100px; 
     float:left; 
    } 
</style> 
</head> 
<body> 
<div class="login_form"> 
<form action="login.php" method="post" > 
    <p> 
     <label for="email">E-mail:</label> 
     <input name="email" type="text" id="email" size="30"/> 
    </p> 
    <p> 
     <label for="password">Password:</label> 
     <input name="pass" type="password" id="pass" size="30"/> 
    </p> 
    <p> 
     <input name="submit" type="submit" value="Submit"/> 
    </p> 
</form> 
</div> 
<?php 
echo $count; 

    session_start(); 
    include('configdb.php'); 
    mysql_select_db("upload_site2", $con); 

// username and password sent from form 
$email=$_POST['email']; 
$pass=$_POST['pass']; 

// To protect MySQL injection (more detail about MySQL injection) 
$email = stripslashes($email); 
$pass = stripslashes($pass); 
$email = mysql_real_escape_string($email); 
$pass = mysql_real_escape_string($pass); 

$sql2=mysql_query("SELECT * FROM registration WHERE email='$email' and password='$pass'"); 
$result=mysql_query($sql2); 
echo $email; 
// Mysql_num_row is counting table row 
$count=mysql_num_rows($result); 
// If result matched $myusername and $mypassword, table row must be 1 row 

if($count==1){ 
// Register $myusername, $mypassword and redirect to file "login_success.php" 
session_register("email"); 
session_register("password"); 
header("location:member.php"); 
} 
else{echo'wrong';} 


?>           

</body> 
</html> 

當我打開此代碼的頁面時,它直接顯示屏幕上的回顯(錯誤),然後我甚至寫電子郵件,並通過.also當我輸入電子郵件,並通過它不重定向到「member.php」,但它保持在同一頁... thnx的幫助登錄和註冊表格

回答

0

爲了解決它的努力,你提交你需要if語句包裹登錄代碼的形式,這將決定是否提交表單之前登錄的問題。

if($_SERVER['REQUEST_METHOD'] == 'POST') 
{ 
    // now do the login code 
} 

它不是重定向的第二個問題可能是由於您的迴音的重定向之前,其發生。在重定向之前,您無法回顯或打印任何內容。因此,刪除所有這些回聲$計數和回聲$電子郵件等。

也檢查您的錯誤日誌或打開錯誤報告的進一步細節。最後,如果您認爲它不起作用,請使用mysql_error()來調試查詢。

打開錯誤報告(在腳本的最頂部):

error_reporting(E_ALL); 
ini_set('display_errors', '1'); 

你有另外一個問題是這樣的代碼:

$sql2=mysql_query("SELECT * FROM registration WHERE email='$email' and password='$pass'"); 
$result=mysql_query($sql2); 

將其更改爲

$sql2 ="SELECT * FROM registration WHERE email='$email' and password='$pass'"; 
$result=mysql_query($sql2); 

if(!$result) 
{ 
    die('error: ' . mysql_error()); // remove this after you have finished debugging 
} 
+0

我試過所有這些但仍然相同problemm ..它不給我任何錯誤 – Paso 2012-03-22 08:17:21

+0

添加後檢查並刪除回顯後顯示新代碼。 – MrCode 2012-03-22 08:30:43

+0

ive推他的代碼,但在差異任務plz看到它overthere..and非常感謝你 – Paso 2012-03-22 08:43:13

0

如果頭已經發送,則不能使用header("location:member.php");。發送標題是因爲您的header函數之前有html字符,而且不僅header,session_register也有同樣的問題。

嘗試:

<?php 

session_start(); 
include('configdb.php'); 
mysql_select_db("upload_site2", $con); 

// username and password sent from form 
$email=$_POST['email']; 
$pass=$_POST['pass']; 

// To protect MySQL injection (more detail about MySQL injection) 
$email = stripslashes($email); 
$pass = stripslashes($pass); 
$email = mysql_real_escape_string($email); 
$pass = mysql_real_escape_string($pass); 

$sql2=mysql_query("SELECT * FROM registration WHERE email='$email' and password='$pass'"); 
$result=mysql_query($sql2); 
echo $email; 
// Mysql_num_row is counting table row 
$count=mysql_num_rows($result); 
// If result matched $myusername and $mypassword, table row must be 1 row 

if($count==1){ 
// Register $myusername, $mypassword and redirect to file "login_success.php" 
session_register("email"); 
session_register("password"); 
header("location:member.php"); 
} 
else{if(!empty($email))$answer='wrong';} 


?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Login</title> 
<style> 
    label{ 
     width:100px; 
     float:left; 
    } 
</style> 
</head> 
<body> 
<div class="login_form"> 
<form action="login.php" method="post" > 
    <p> 
     <label for="email">E-mail:</label> 
     <input name="email" type="text" id="email" size="30"/> 
    </p> 
    <p> 
     <label for="password">Password:</label> 
     <input name="pass" type="password" id="pass" size="30"/> 
    </p> 
    <p> 
     <input name="submit" type="submit" value="Submit"/> 
    </p> 
</form> 
</div> 
<?=$answer?>          

</body> 
</html> 
+0

還是它不是重定向到第二頁:: S:小號 – Paso 2012-03-22 08:06:10

+0

添加'的error_reporting(E_ALL)''之前在session_start();'和檢查,也許你有一些其他錯誤。 – Narek 2012-03-22 08:11:06

+0

什麼也沒有發生 – Paso 2012-03-22 08:16:55

0

重定向頁面後添加exit();

+0

它沒有工作:S – Paso 2012-03-22 09:02:02

+0

它是否進入裏面如果($ count == 1)條件? – heyanshukla 2012-03-22 09:06:46

0
<?php 
    session_start(); 
    if (!isset($_SESSION['email'])) { 
header('Location: index.php'); 

} 
echo $_SESSION['email']; 

?> 
<html> 

<head> 
<title>Secured Page</title> 
</head> 

<body> 

<p>This is secured page with session: <b><?php echo $_SESSION['email']; ?></b> 
<br>You can put your restricted information here.</p> 
<p><a href="logout.php">Logout</a></p> 


<form action="upload.php" method="post" enctype="multipart/form-data"> 
     <input type="file" name="uploaded_file"><br> 
     <input type="submit" value="Upload" name="upload"> 
    </form> 
    <p> 
     <a href="list_files.php">See all files</a> 
    </p> 




</body> 
</html> 

這是member.php