Jump to content

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" ;

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.