Jump to content

Recommended Posts

Hi Guys,

 

I am currently using sessions on all of my pages using the username field. But how do I retrieve the empID of the person logged in?!

 

my session code is

 

<?php

session_start();

if (isset($_SESSION['username']) == false){

header("Location: login.php");

exit();

}

require "connect.php";

$query = "select * from employee where username = '".$_SESSION['username']."'";

$result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query");

?>

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/84888-solved-getting-variables-from-a-session/
Share on other sites

You're not pulling the ID from the Session, you are pulling it from the Database with your Query command.  What are you doing after this line?

 

$result = mysql_query($query, $connection) or die ("Unable to perform query $query");

 

This is what follows that...

It is a form asking the user to fill in the details of the meeting room they wish to book, i also want it to write into the table their empID which is not requested on the form but want it to be carried through to my query page (shown after).

 

<body>

<?php

include ("header.php");

?>

<h2>Book a Meeting Room</h2>

<h3>

<form action="MeetingQuery.php" method="get">

  <table width="99%" border="0">

    <tr>

      <td width="29%">Select a building:</td>

      <td width="34%"><select name="building">

        <option >[select a Building]</option>

        <option >North</option>

        <option >South</option>

      </select></td>

      <td width="22%"> </td>

      <td width="15%"> </td>

      </tr>

    <tr>

      <td> </td>

      <td> </td>

      <td> </td>

      <td> </td>

      </tr>

    <tr>

      <td>Select a Meeting Room: </td>

      <td><select name="roomID">

        <option >[select Meeting Room Number]</option>

        <option >020</option>

        <option >021</option>

        <option >105</option>

        <option >106</option>

        <option >113</option>

        <option >215</option>

        <option >216</option>

      </select></td>

      <td> </td>

      <td> </td>

      </tr>

    <tr>

      <td> </td>

      <td> </td>

      <td> </td>

      <td> </td>

      </tr>

    <tr>

      <td>Select a Date: </td>

      <td><p><script>DateInput('bkgDate', true, 'DD-MON-YYYY')</script></p></td>

      <td>Select a Time: </td>

      <td><select name="bkgTime">

        <option >[select Meeting Time]</option>

        <option >0900-1000</option>

        <option >1000-1100</option>

        <option >1100-1200</option>

        <option >1200-1300</option>

        <option >1300-1400</option>

        <option >1400-1500</option>

        <option >1500-1600</option>

        <option >1600-1700</option>

      </select></td>

      </tr>

    <tr>

      <td> </td>

      <td> </td>

      <td> </td>

      <td> </td>

      </tr>

    <tr>

      <td> </td>

      <td><?php

 

if(isset($_GET['message1']))

{

echo $_GET['message1'];

}

else if(isset($_GET['message2']))

{

echo $_GET['message2'];

}

else if(isset($_GET['message3']))

{

echo $_GET['message3'];

}

?></td>

      <td> </td>

      <td> </td>

      </tr>

    <tr>

      <td> </td>

      <td> </td>

      <td> </td>

      <td> </td>

      </tr>

    <tr>

      <td><input name="empID" value="<?=$_SESSION['empID']?>" /></td>

      <td> </td>

      <td><input name="Save" type="submit" value="Submit Meeting Room" /></td>

      <td> </td>

      </tr>

  </table>

  </form>

</body>

</html>

 

QUERY PAGE

<?php

require "connect.php";

$roomID = $_GET['roomID'];

$building = $_GET['building'];

$bkgDate = $_GET['bkgDate'];

$empID = $_GET['empID'];

 

if($building == "[select a Building]")

{

$message1 = "Please select a building you wish to have the meeting in";

header("Location: MeetingMain.php?message1=$message1");

exit();

}

if($roomID == "[select Meeting Room Number]")

{

$message2 = "Please select a Room Number";

header("Location: MeetingMain.php?message2=$message2");

exit();

}

if($bkgTime == "[select Meeting Time]")

{

$message3 = "Please select a Meeting Time";

header("Location: MeetingMain.php?message3=$message3");

exit();

}

 

else if($building == !null || $roomID == !null)

{

$query = "insert into booking ('','".$roomID."','".$empID."','".$bkgDate."','".$bkgTime."')";

$result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query");

//$message7 = "'".$fName."' '".$sName."' added successfully. ";

//header("Location: UserADD.php?message7=$message7");

exit();

}

?>

Ye, my session is declared in my logincheck.php page.

 

This is it...

 

<?php

session_start();

require "connect.php";

$username = $_POST['username'];

$password = $_POST['password'];

$query = "select * from employee WHERE active ='y' AND username='".$username."' AND password='".$password."'";

 

 

$result = mysql_query($query, $connection) or die ("Unable to perform query<br>$query");

 

$row=mysql_fetch_array($result);

 

if($row!=null)

{

$_SESSION['username'] = $row['username'];

header("Location: welcome.php");

exit();

}

else if($username == "")

{

$message2 = "Please enter your Username";

header("Location: login.php?message2=$message2");

exit();

}

else if($password == "")

{

$message3 = "Please enter your Password";

header("Location: login.php?message3=$message3");

exit();

}

/*else if(active = "n")

{

$message4 = "Sorry, this users account has been de-activated. Please contact the system administrator."

header("Location: login.php?message4=$message4");

exit();

}*/

else

{

$message = "Invalid user name or password, please try again";

header("Location: login.php?message=$message");

exit();

}

?>

$_SESSION['username'] = $row['username'];

      header("Location: welcome.php");

      exit();

 

to

 

$_SESSION['username'] = $row['username'];

$_SESSION['empID'] = $row['empID'];

 

      header("Location: welcome.php");

      exit();

 

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.