Jump to content

Recommended Posts

I know. But that was just to prove that the PHP code itself is correct and that it is the session that is causing the problem. Where are you setting the $_SESSION['employeeID']? Does the page that you set that also have session_start()? By the way, I am planning to stay up to 8PM EST to answer any questions before I have other matters to attend to so hopefully we can get this working by then.

I assume the only reason you are using a session is because you don't want anyone to know the employee ID since they can hack your database. But with the way it is currently being set up, I don't think that it matters since it is hackable either way. Anyway, that is beside the point. The easy solution now is that you can only use the GET to send the employee ID.

The updating of the data is apart of the admin section of my system and i have set up sessions whereby you have to login before you can view any of the admin pages and if you try and jump pages it will take you back to the login screen.

But i am putting my sessions at the end once all the admin pages are created.

I understand the concepts of sessions but just confused over the problem in hand and why it doesnt return a value :-(

 

 

 

I don't exactly understand your last sentence there. But the problem is that the session is not being passed onto that page that is updating the user information. I don't fully know the reason why but the only thing I can think off is that you missed the session_start() when you are setting the session.

Sorry this is slowly going over my head :-S

 

the code below -

 

<?php

  session_start();

  require "connect.php";

  $employeeID = $_SESSION['employeeID'];

  $title = $_GET['title'];

  $firstname = $_GET['firstname'];

  $surname = $_GET['surname'];

  $username = $_GET['username'];

  $password = $_GET['password'];

    $query = "update employee set title =' ".$title." ', firstname =' ".$firstname." ', surname =' ".$surname." ', username =' ".$username." ', password =' ".$password.    " ' where employeeID = ".$employeeID;

  $result = mysql_query($query, $connection) or die ('Unable to perform query: '.$query.'

    Error: '.mysql_error());

  header("Location: displayEmployeeAdmin.php");

  exit();

?>

 

has a session in the displayEmployeeForm.php (bottom of the code)

 

And in the displayEmployeeForm.php file, right at the top (line 1)it has the following session (PHP code)

 

 

<?php

session_start();

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

header("Location:Adminlogin.php");

exit();

}

?>

 

If this helps.

 

 

 

 

 

 

so like this

 

<?php

  session_start();

  require "connect.php";

  $employeeID = $_SESSION['employeeID'] = 1;

  $title = $_GET['title'];

 

Adding the 1 at the end of employeeID, but isnt that making it static again ?

 

 

i think this is what your looking, its my login script.

 

<?php

session_start();

require "connect.php";

$username = $_GET['username'];

$password = $_GET['password'];

$query = "select * from admin where 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: AdminMainPage.php");

exit();

}

else

{

$message = "Invalid UserName or Password, Please Try Again";

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

exit();

}

?>

LOL good job

 

now this line add this $_SESSION['employeeID'] = $row['employeeID'];

 

 

$_SESSION['employeeID'] = $row['employeeID'];//<--- employeeID should be the field in your table

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

      header("Location: AdminMainPage.php");

Hi it does work THANKS but this has occured.

 

This is screen where i edit the data.

 

e.g

 

In my database i have 5 users in the employee table.

 

If i edit changes in user 5, then the details in the first user gets deleted and replaced by the details of user 5.

 

So it does update but deletes the first row.

 

I hope this makes sense.

 

 

 

 

 

<?php

  session_start();

  require "connect.php";

  $employeeID = $_SESSION['employeeID'];

  $title = $_GET['title'];

  $firstname = $_GET['firstname'];

  $surname = $_GET['surname'];

  $username = $_GET['username'];

  $password = $_GET['password'];

    $query = "update employee set title =' ".$title." ', firstname =' ".$firstname." ', surname =' ".$surname." ', username =' ".$username." ', password =' ".$password.    " ' where employeeID = ".$employeeID;

  $result = mysql_query($query, $connection) or die ('Unable to perform query: '.$query.'

    Error: '.mysql_error());

  header("Location: displayEmployeeAdmin.php");

  exit();

?>

 

 

This is the displayEmployeeAdmin.php script, this displays the data in the DB ready for me to edit and calls the above script for updating.

 

 

 

<?php

session_start();

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

header("Location:Adminlogin.php");

exit();

}

?>

 

<?php

 

require "connect.php";

$query = "select * from employee";

$result = mysql_query($query, $connection)

or die ("MySQL Error: ".mysql_error());

 

?>

 

<head>

<title>Jupiter Development Support</title>

<link href="Images/mystyle.css" rel="stylesheet" type="text/css">

<style type="text/css">

<!--

#Layer2 {position:absolute;

width:174px;

height:48px;

z-index:2;

left: 16px;

top: 143px;

}

#Layer1 {position:absolute;

width:200px;

height:76px;

z-index:1;

left: 254px;

top: 84px;

}

.style1 {

font-family: "Copperplate Gothic Bold";

font-size: x-large;

}

#Layer3 {

position:absolute;

width:177px;

height:34px;

z-index:3;

left: 498px;

top: 218px;

}

.style6 {font-size: medium; font-family: "Copperplate Gothic Bold";}

.style7 {font-size: small}

#Layer6 { position:absolute;

width:117px;

height:115px;

z-index:4;

left: 945px;

top: 195px;

}

#Layer10 { position:absolute;

width:200px;

height:115px;

z-index:10;

left: 992px;

top: 200px;

}

#Layer4 {

position:absolute;

width:200px;

height:73px;

z-index:11;

left: 272px;

top: 295px;

}

#Layer5 { position:absolute;

width:158px;

height:43px;

z-index:11;

left: 52px;

top: 310px;

}

#Layer8 { position:absolute;

width:158px;

height:42px;

z-index:13;

left: 51px;

top: 361px;

}

#Layer7 {

position:absolute;

width:157px;

height:42px;

z-index:14;

left: 50px;

top: 410px;

}

-->

</style>

</head>

<body>

 

<div id="header">

<p> </p>

<p> </p>

<div id="Layer1"><img src="Images/JDS.jpg" width="704" height="79"></div>

<p> </p>

<div id="Layer2"><img src="Images/logo.jpg" width="173" height="43"></div>

<p> </p>

<p> </p>

<table width="975" height="194" border="0">

  <tr>

    <td width="26" height="26"> </td>

    <td width="123"><div id="Layer5"><a href="AdminMainPage.php"><img src="Images/AdminHomepagebutton.jpg" width="158" height="42" border="0"></a></div></td>

    <td width="79"></td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="86"> </td>

  </tr>

 

  <tr>

    <td height="56"> </td>

    <td> </td>

    <td><div id="Layer3"><span class="style1">Edit User</span></div></td>

    <td width="130"><div align="center" class="style6">Title</div></td>

    <td width="130"><div align="center" class="style6">FirstName</div></td>

    <td width="130"><div align="center" class="style6">Surname</div></td>

    <td width="130"><div align="center" class="style6">Username</div></td>

    <td width="130"><div align="center" class="style6">Password</div></td>

  </tr>

  <tr>

    <td height="21"> </td>

    <td> </td>

    <td> </td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="86"> </td>

  </tr>

  <tr>

    <td height="41"> </td>

    <td> </td>

<td><?php

while($row= mysql_fetch_array($result)){?></td>

    <td width="130"><div align="center" class="style7"><?php echo $row['title'];?>

      <div id="Layer10"><img src="Images/Symbol.jpg" width="235" height="231"></div>

    </div></td>

 

    <td width="130"><div align="center" class="style7"><?php echo $row['firstname'];?></div></td>

    <td width="130"><div align="center" class="style7"><?php echo $row['surname'];?></div></td>

    <td width="130"><div align="center" class="style7"><?php echo $row['username'];?></div></td>

    <td width="130"><div align="center" class="style7"><?php echo $row['password'];?></div></td>

<td><a href="EditUserForm.php?employeeID=<?php echo $row['employeeID'];?>"><img src="Images/smallUpdateButton.jpg" width="67" height="25"></td>

  </tr>

  <tr>

    <td height="38"> </td>

    <td><div id="Layer7"><a href="deletepersonScreen.php"><img src="Images/deleteUser.jpg" width="158" height="41" border="0"></a></div></td>

    <td><?php } ?></td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="130"> </td>

    <td width="86"> </td>

  </tr>

</table>

<div id="Layer8"><a href="CreateUser.php"><img src="Images/createUserButton.jpg" width="158" height="42" border="0"></a></div>

<p> </p>

<p><br/>

</p>

</p>

</body>

 

This peice of code below, is a loop which displays each record of the table EMPLOYEE

 

while($row= mysql_fetch_array($result)){?></td>

    <td width="130"><div align="center" class="style7"><?php echo $row['title'];?>

      <div id="Layer10"><img src="Images/Symbol.jpg" width="235" height="231"></div>

    </div></td>

 

    <td width="130"><div align="center" class="style7"><?php echo $row['firstname'];?></div></td>

    <td width="130"><div align="center" class="style7"><?php echo $row['surname'];?></div></td>

    <td width="130"><div align="center" class="style7"><?php echo $row['username'];?></div></td>

    <td width="130"><div align="center" class="style7"><?php echo $row['password'];?></div></td>

<td><a href="EditUserForm.php?employeeID=<?php echo $row['employeeID'];?>"><img src="Images/smallUpdateButton.jpg" width="67" height="25"></td>

  </tr>

  <tr>

    <td height="38"> </td>

    <td><div id="Layer7"><a href="deletepersonScreen.php"><img src="Images/deleteUser.jpg" width="158" height="41" border="0"></a></div></td>

    <td><?php } ?>

 

 

Hope this makes sense :-)

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.