Jump to content

[SOLVED] Is this statement right..if not how do I write this?


derekbelcher

Recommended Posts

I am trying to switch from the antique code to what is recognized today.

 

Previous code that worked fine:

 

if(!session_is_registered(myusername)){

header("location: and so on.

 

What I want to use is $_SESSION.

 

I tried this:

 

if($_SESSION[(myusername)]{

header("location: and so on.

 

Can someone help me find the error of my way :-)  Thanks.

thank you.  Now next question:

 

I had this code which output the first and last name of the person with the user id that was used at login, and now it won't work.  It worked with session_is_registered,  but not with the new $_SESSION.

 

<?PHP

 

$firstname = $_POST['firstname'] ;

$lastname = $_POST['lastname'] ;

$user = $_POST['username'] ;

 

$sql = "SELECT * FROM `officers` WHERE username = '{$_SESSION['myusername']}'" ;

 

$result = mysql_query($sql) ;

 

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

 

  $dbfname = $row['firstname'] ;

  $dblname = $row['lastname'] ;

  $dbuser = $row['username'] ;

}

 

echo "$dbfname $dblname" ;

 

?>

Well, from what I saw, you never defined the $_SESSION['username'] variable, but you are defining the $user from the $_POST variable, so use that:

<?PHP

$firstname = $_POST['firstname'] ;
$lastname = $_POST['lastname'] ;
$user = $_POST['username'] ;
// use the $user here instead
$sql = "SELECT * FROM `officers` WHERE username = '".$user."'" ;

$result = mysql_query($sql) ;

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{

   $dbfname = $row['firstname'] ;
   $dblname = $row['lastname'] ;
   $dbuser = $row['username'] ;
}

echo "$dbfname $dblname" ;

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.