Re: Session won't pick up one variable
| From: | Shawn McKenzie | Date: | Fri, 30 Jan 2009 23:44:58 +0000 |
| Subject: | Re: Session won't pick up one variable | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-287463@lists.php.net to get a copy of this message | ||
Terion Miller wrote:
> Well I changed it because it's not a post since its not coming from a form
> is this closer?
>
> if (!empty($UserName)) {
>
Why are you doing this? Only to see if > 0 rows are returned? You can
use the results you know.
> $sql = "SELECT
>
AdminID,UserName FROM
> admin WHERE
> UserName='$UserName' and
> Password='$Password'";
> $result = mysql_query ($sql);
> $row = mysql_fetch_object ($result);
Do you maybe mean $row['AdminID']? Well you're using objects now so
$row->AdminID?
> $AdminId = $_SESSION['AdminID'];
>
What in the hell are you doing here? If it's set then set it again to
equal itself?
> if(isset($_SESSION['AdminID']))
> $_SESSION['AdminID'] = $_SESSION['AdminID'];
> else
> $_SESSION['AdminID'] = $AdminID;
>
> If (mysql_num_rows($result) > 0) {
> $_SESSION['AdminLogin'] = true;
> $_SESSION['user']=$UserName;
> $_SESSION['AdminID']=$AdminID;
>
> header ('Location: Main.php');
> exit;
> } else {
You either need to get a good PHP book or pay much closer attention to
what you're doing. Many more problems, but those seem to cause your
issue. This is not complete but seems to be the structure you need:
session_start();
include("inc/dbconn_open.php");
if (!empty($_POST['UserName']) && !empty($_POST['Password'])) {
$UserName = $_POST['UserName'];
$Password = $_POST['Password'];
$sql = "SELECT AdminID,UserName FROM admin WHERE
UserName='$UserName' and
Password='$Password'";
$result = mysql_query ($sql);
$row = mysql_fetch_object ($result);
If (mysql_num_rows($result) > 0) {
$_SESSION['AdminLogin'] = true;
$_SESSION['user'] = $UserName;
$_SESSION['AdminID'] = $row->AdminID;
header ('Location: Main.php');
exit;
} else {
--
Thanks!
-Shawn
http://www.spidean.com