Re: Help w/ $_SESSION

From: Date: Tue, 12 Nov 2002 08:03:23 +0000
Subject: Re: Help w/ $_SESSION
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-123945@lists.php.net to get a copy of this message
Also the echo statement is just there for testing purposes to make sure the variable were containing the correct data. Lee "Conbud" <conbudd@yahoo.com> wrote in message news:20021112075942.16291.qmail@pb1.pair.com... > Hey, > I do have it in a variable but I just choose to leave it out. > Ive tried so many different things with this and even what you gave me for > some reason didnt work. The variables are being set, if I echo > $_SESSION['user'] then right data is shown. However as soon as I put it in > the mysql_query it stops working. Im using it for a login script that I > include at the start of every page. Heres what I got: > > <?php > session_start(); > ?> > <?php > $_SESSION['user'] = $_POST['user']; > $_SESSION['pass'] = $_POST['pass']; > ?> > <?php > $db = mysql_connect("$host", "user", "pass"); > mysql_select_db("$dtb",$db); > $result = mysql_query("select count(*) AS numfound from admins where > user='{$_SESSION['user']}' AND > pass='{$_SESSION['pass']}'",$db); > echo "".$_SESSION['user']." > ".$_SESSION['pass'].""; > > $result_ar = mysql_fetch_array($result); > if ($result_ar['numfound'] < 1) > { > session_unset(); > session_destroy(); > include("error.php"); > exit; > } > ?> > > I include that at the top of every page I want to protect. > > Lee > > "Jason Wong" <php-general@gremlins.com.hk> wrote in message > news:200211121537.49604.php-general@gremlins.com.hk... > > On Tuesday 12 November 2002 15:05, conbud wrote: > > > Hey, > > > How would I insert $_SESSION['user'] and $_SESSION['pass'] > > > > > > into this > > > mysql_query("select count(*) AS numfound from admins where user='$user' > AND > > > pass='$pass'",$db); > > > > > > right now I have > > > $_SESSION['user'] = $_POST['user'] > > > $_SESSION['pass'] = $_POST['pass'] > > > > > > and I need to put $_SESSION['user'] where the $user is in the above > > > statement and so one w/ $pass > > > > You mean like this? > > > > mysql_query("select count(*) AS numfound from admins where > > user='{$_SESSION['user']}' AND > > pass='{$_SESSION['pass']}'",$db); > > > > BTW, it is much better to assign your query to a variable, eg $qry, then > do > > > > mysql_query($qry, $db) or die('Error in $qry ' . mysql_error()); > > > > That way if your query doesn't work you'll at least know why. > > > > -- > > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk > > Open Source Software Systems Integrators > > * Web Design & Hosting * Internet & Intranet Applications Development * > > > > /* > > Perhaps the biggest disappointments were the ones you expected anyway. > > */ > > > >

« previous php.general (#123945) next »