duclet Posted January 2, 2008 Share Posted January 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427675 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 can i ask why do you need the session to be use in your query ? Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427688 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 The session around the employee does not need to be there, that was advised to me by a friend who is doing something similar to me, but dont think his is working either. Â Â Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427693 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 Can this be done without the session then ? Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427695 Share on other sites More sharing options...
duclet Posted January 2, 2008 Share Posted January 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427698 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 i think you dont know how the use of session .. and you dont know how it works <a href="http://www.w3schools.com/php/php_sessions.asp">read </a> first Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427701 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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 :-( Â Â Â Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427705 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 whereby you have to login before you can view any of the admin pages  then show that file that determine that you're allowed to view the page or the part where you set those sessions Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427711 Share on other sites More sharing options...
duclet Posted January 2, 2008 Share Posted January 2, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427715 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 it will not be passed if it is not set like he said it works when he put static value Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427720 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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.       Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427728 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 if you can find where this var $_SESSION['username'] you should be fine all yo have to dos is add a line saying $_SESSION['employeeID'] = somestuff here; Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427729 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 add a line saying $_SESSION['employeeID'] = somestuff here;   Sorry abit bambozzled, where would i put that extra line you were saying and what do you mean by somestuff ?     Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427734 Share on other sites More sharing options...
duclet Posted January 2, 2008 Share Posted January 2, 2008 Add that line to the place where you have the employee ID number. The somestuff is the id itself. Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427736 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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 ?   Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427744 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 lol... ok to simplify this find this code in your pages and post that here then we're done  $_SESSION['username'] = 'there should a value here comming form your sql select';   Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427747 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427756 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 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"); Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427760 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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.      Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427779 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 can you show mw your code now... ??? Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427782 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 <?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>  Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427786 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 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 :-) Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427788 Share on other sites More sharing options...
teng84 Posted January 2, 2008 Share Posted January 2, 2008 lol makes no sense.. it is impossible that you record is deleted because i dont see a query for deletion well do you have it? Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-427832 Share on other sites More sharing options...
taz321 Posted January 2, 2008 Author Share Posted January 2, 2008 Thanks for all ur help guys, its not quite working yet but il keep trying and playing around with things. Â Quote Link to comment https://forums.phpfreaks.com/topic/84019-solved-updating-data-in-a-database/page/2/#findComment-428347 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.