0

我有一个 account.php 页面,用户可以在其中更改保存在 mySQL 数据库中的帐户信息。当我单击它的链接时,我收到一条消息,提示“在访问此页面之前返回并登录!” 我的代码如下。

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.
?>

帐户.php

<?php
session_start()
?>
4

1 回答 1

1

也放在页面session_start()顶部pro.php

于 2013-03-30T21:30:28.927 回答