danielbala Posted February 17, 2012 Share Posted February 17, 2012 Hi.... im just trying to display the current login user's fullname in the field Current employee name in a file..i did the current user name to be displayed This is code. <?php session_start(); if (isset($_SESSION['id'])){ $loginid=$_SESSION['id']; } if (isset($_SESSION['T_UserName'])){ $T_UserName=$_SESSION['T_UserName']; } if (isset($_GET['id'])){ $loginid=$_GET['id']; //Get login username if using GET $loginid=mysql_real_escape_string($loginid); $query = "SELECT `username` FROM `details` WHERE id=$loginid"; $result = mysql_query($query); $row = mysql_fetch_row($result); $T_UserName=$row[0]; } ?> <?php if (isset($_SESSION['emp_id'])){ $loginid=$_SESSION['emp_id']; } if (isset($_SESSION['emp_name'])){ $CurrentEmpName=$_SESSION['emp_name']; } if (isset($_GET['emp_id'])){ $loginid=$_GET['emp_id']; //Get login username if using GET $loginid=mysql_real_escape_string($loginid); $query = "SELECT `emp_name` FROM `login` WHERE emp_id=$loginid"; $result = mysql_query($query); $row = mysql_fetch_row($result); $CurrentEmpName=$row[0]; } ?> this is form.. <form action="" method="post" enctype="multipart/form-data" name="employee" target="_self"> <br /> <br /> <table border="1"> <tr width="569" colspan="2"> <td> Current User : <input name="CurrentUser" type="text" disabled id="UserId" size="35" maxlength="35" readonly class="disabled" value="<?php echo $_SESSION['username'];?>"/> Activity : <input name="LogActivity" type="text" disabled id="ActLog" size="35" Value="List New Jobs" maxlength="35" readonly class="disabled" /> <br /> Current Employee Name : <input name="CurrentEmpName" type="text" disabled id="CurrentEmpId" size="35" maxlength="35" readonly class="disabled" value="<?php echo $_SESSION['emp_name'];?>"/> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/ Share on other sites More sharing options...
Muddy_Funster Posted February 17, 2012 Share Posted February 17, 2012 You are using the $_SESSION['emp_name'] session variable in the form to display the value, but no where in your code do you assign a value to this variable.... also you are using the POST method in your form, and the GET method in your code.... and you have duplicate code for the GET check.... Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318307 Share on other sites More sharing options...
danielbala Posted February 17, 2012 Author Share Posted February 17, 2012 How to do..im new newbie to php :( Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318311 Share on other sites More sharing options...
danielbala Posted February 17, 2012 Author Share Posted February 17, 2012 please i dont know whether my code is correct or not?? Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318329 Share on other sites More sharing options...
cyberRobot Posted February 17, 2012 Share Posted February 17, 2012 @danielbala - Did you create the code? The script looks like it was made to gather input from multiple pages. Some access the script via $_SESSION variables, while others use $_GET variables. However, the code provided doesn't show what happens when dealing with $_POST variables. Is there more code that's not being shown? Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318336 Share on other sites More sharing options...
danielbala Posted February 17, 2012 Author Share Posted February 17, 2012 nope this is the only code not gathered.. Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318340 Share on other sites More sharing options...
cyberRobot Posted February 17, 2012 Share Posted February 17, 2012 Hmm...there has to be more code somewhere. As Muddy_Funster asked, where is $_SESSION['emp_name'] being set? Note that it could have been set somewhere else on the website. Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318343 Share on other sites More sharing options...
danielbala Posted February 17, 2012 Author Share Posted February 17, 2012 I already gave isset($_SESSION['emp_name']; Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318347 Share on other sites More sharing options...
cyberRobot Posted February 17, 2012 Share Posted February 17, 2012 I already gave isset($_SESSION['emp_name']; All that does is check if $_SESSION['emp_name'] has been set. The code would look more like: <?php $_SESSION['emp_name'] = $name; ?> Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318349 Share on other sites More sharing options...
danielbala Posted February 17, 2012 Author Share Posted February 17, 2012 i gave as if (isset($_SESSION['emp_name'])){ $CurrentEmpName=$_SESSION['emp_name']; } is not correct??? Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318351 Share on other sites More sharing options...
cyberRobot Posted February 17, 2012 Share Posted February 17, 2012 If you attempt to display $_SESSION['emp_name'] as show below, what does it display? <?php //... var_dump($_SESSION['emp_name']); //<--- ADD THIS CODE BEFORE YOUR IF STATEMENT if (isset($_SESSION['emp_name'])){ $CurrentEmpName=$_SESSION['emp_name']; } //... ?> Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318355 Share on other sites More sharing options...
danielbala Posted February 17, 2012 Author Share Posted February 17, 2012 im getting this error Parse error: syntax error, unexpected T_IF in C:\w Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318357 Share on other sites More sharing options...
cyberRobot Posted February 17, 2012 Share Posted February 17, 2012 Sounds like you may have missed the semi-colon after the var_dump(). <?php var_dump($_SESSION['emp_name']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318362 Share on other sites More sharing options...
danielbala Posted February 17, 2012 Author Share Posted February 17, 2012 im getting null and above that im getting this error also Undefined index: emp_name Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318364 Share on other sites More sharing options...
cyberRobot Posted February 17, 2012 Share Posted February 17, 2012 NULL means that $_SESSION['emp_name'] has not been set. Since the variable isn't set, the code inside the following if statement will not execute: <?php if (isset($_SESSION['emp_name'])){ $CurrentEmpName=$_SESSION['emp_name']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318368 Share on other sites More sharing options...
danielbala Posted February 17, 2012 Author Share Posted February 17, 2012 where to set the variabale?? Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318370 Share on other sites More sharing options...
danielbala Posted February 17, 2012 Author Share Posted February 17, 2012 Where to set the variable?? Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318374 Share on other sites More sharing options...
cyberRobot Posted February 17, 2012 Share Posted February 17, 2012 Where to set the variable?? To be honest, I don't know. Since I'm not very familiar with how the code relates to the rest of the website, it's difficult to say where the $_SESSION variable needs to be set. The only thing I can say is that it needs to be set somewhere in the website where you know employee's name...which is probably on the page before getting to the form. Note that I don't have a lot of time (right now) to help with the issue. Of course, you can still post more questions / code. Maybe someone else will be able to help...or maybe I'll be able to help later. Quote Link to comment https://forums.phpfreaks.com/topic/257174-help-me/#findComment-1318382 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.