2013-03-30 42 views
0

我有一個account.php頁面,用戶可以更改保存在mySQL數據庫上的帳戶信息。當我點擊鏈接時,我會收到一條消息,說「在訪問此頁之前回去登錄!」我的代碼如下。會話沒有通過

pro.php(涉及一次登錄頁)在pro.php頁面頂部

<?php 

//STEP 1 Connect To Database 
$connect = mysql_connect("Localhost","mlec2013_danny","8764963d"); 
if (!$connect) 
{ 
die("MySQL could not connect!"); 
} 

$DB = mysql_select_db('mlec2013_database'); 

if(!$DB) 
{ 
die("MySQL could not select Database!"); 
} 

//STEP 2 Declare Variables 

$Name = $_POST['username']; 
$Pass = $_POST['password']; 
$Query = mysql_query("SELECT * FROM Users WHERE Username='$Name' AND Password='$Pass'"); 
$NumRows = mysql_num_rows($Query); 
$_SESSION['username'] = $Name; 
$_SESSION['password'] = $Pass; 

//STEP 3 Check to See If User Entered All Of The Information 

if(empty($_SESSION['username']) || empty($_SESSION['password'])) 
{ 
die("Go back and login before you visit this page!"); 
} 

if($Name && $Pass == "") 
{ 
die("Please enter in a name and password!"); 
} 

if($Name == "") 
{ 
die("Please enter your name!" . "</br>"); 
} 

if($Pass == "") 
{ 
die("Please enter a password!"); 
echo "</br>"; 
} 

//STEP 4 Check Username And Password With The MySQL Database 

if($NumRows != 0) 
{ 
while($Row = mysql_fetch_assoc($Query)) 
{ 
$Database_Name = $Row['username']; 
$Database_Pass = $Row['password']; 
} 
} 
else 
{ 
die("Incorrect Username or Password!"); 
} 


//end of PHP scripting. Information displayed below is in the form of HTML, CSS, or Javascript. 
?> 

account.php

<?php 
session_start() 
?> 

回答

1

地點session_start()爲好。

+0

當我這樣做時,它將其標記爲語法錯誤 –

+1

可能您忘記輸入';'如'session_start();' – 2013-03-30 21:33:09

+1

啊!而已。不能相信我是一個愚蠢的錯誤。謝謝!!! –