-2
我有一個登錄腳本,它在我的主頁我的登錄表單,這也是在我的主頁。當用戶提交表單登錄時,他/她提交他/她的用戶名和密碼。從一個頁面發送隱變量到另一個
腳本訪問數據庫具有用戶名,密碼和電子郵件來自注冊用戶存儲的地址。
一旦用戶登錄成功,他/她將被重定向到其在同一數據庫中存儲不同的表內的網頁上加載他們以前的「評論」頁面。
我需要從一個表發送電子郵件到查詢重定向的頁面上。
這裏是我的PHP代碼,處理登錄的代碼:
<?php
//If the user has submitted the form
if(isset($_REQUEST['username'])){
//protect the posted value then store them to variables
$username = protect($_POST['username']);
$password = protect($_POST['password']);
//Check if the username or password boxes were not filled in
if(!$username || !$password){
//if not display an error message
echo "<center>You need to fill in a <b>Username</b> and a <b>Password</b>!</center>";
}else{
//if they were continue checking
//select all rows from the table where the username matches the one entered by the user
$res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'");
$num = mysql_num_rows($res);
//check if there was no match
if($num == 0){
//if none, display an error message
echo "<center>The <b>Username</b> you supplied does not exist!</center>";
}else{
//if there was a match continue checking
//select all rows where the username and password match the ones submitted by the user
$res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."' AND `password` = '".$password."'");
$num = mysql_num_rows($res);
//check if there was no match
if($num == 0){
//if none display error message
echo "<center>The <b>Password</b> you supplied does not match the one for that username!</center>";
}else{
//if there was continue checking
//split all fields from the correct row into an associative array
$row = mysql_fetch_assoc($res);
//check to see if the user has not activated their account yet
if($row['active'] != 1){
//if not display error message
echo "<center>You have not yet <b>Activated</b> your account!</center>";
}else{
//if they have log them in
//set the login session storing there id - we use this to see if they are logged in or not
$_SESSION['uid'] = $row['id'];
//update the online field to 50 seconds into the future
$time = date('U')+50;
mysql_query("UPDATE `users` SET `online` = '".$time."' WHERE `id` = '".$_SESSION['uid']."'");
//redirect them to the usersonline page
echo 'REDIRECT';
}
}
}
}
exit;
}
?>
這裏是PHP代碼,就重新定向到頁面:
<?php
$con=mysqli_connect("","","","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM comments
WHERE email='$_POST[email]' ORDER BY dt");
while($row = mysqli_fetch_array($result))
{
echo $row['dt'] ." " . $row['email'] . " " . $row['body'];
echo "<br>";
echo "<br>";
}
?>
我需要添加第一個代碼從表格中提取電子郵件地址,以驗證登錄信息並將其發送到第二個代碼以接收「評論」。我試着用Google搜索一個答案,並沒有提出任何建議。請幫忙!
我將此代碼放入處理登錄信息的腳本中。評論仍未顯示在登錄屏幕中。我把代碼放在了錯誤的地方嗎? – user2109152 2013-03-28 07:23:09
'電子郵件= $ _ POST [郵件]''你重定向代碼也需要'而不是$ _SESSION''$ _POST' – 2013-03-28 07:25:41
檢查最近編輯@ user2109152感謝巴特。 – hjpotter92 2013-03-28 07:32:55