derekbelcher Posted April 22, 2009 Share Posted April 22, 2009 I am trying to display the first and last name of the person that is logged into my site. I am using the following Code to try to do this. Can someone point out what I am missing as nothing is displayed (first / last name) when you log in. It worked when I was using session_is_registered, but I was told that I should get away from that and use $_SESSION. Thanks for any info... Code: <? ini_set("session.cookie_lifetime", "60"); session_save_path(); session_start(); if (isset($_SESSION['myusername'])) { header("location:officerLogin.php"); } ?> <?php $host="localhost"; // Host name $username="athens"; // Mysql username $password="avfd1179"; // Mysql password $db_name="athens_officerArea"; // Database name $tbl_name="officers"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); ?> <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Officer's Area</title></head> <body> <table cellpadding="0" cellspacing="0" width="688" height="583" align="center"> <!--DWLayoutTable--> <!-- MSTableType="layout" --> <tr> <td height="19" colspan="3" valign="top">Welcome <b><?PHP $firstname = $_POST['firstname'] ; $lastname = $_POST['lastname'] ; $user = $_POST['username'] ; $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" ; ?></b></td> </tr> <tr> <td height="80" colspan="3" valign="top"> <p style="margin-top: 0; margin-bottom: 0"> <font face="georgia, bookman old style, palatino linotype, book antiqua, palatino, trebuchet ms, helvetica, garamond, sans-serif, arial, verdana, avante garde, century gothic, comic sans ms, times, times new roman, serif"> <i><font size="4">When a man becomes a fireman his greatest act of bravery has been accomplished. What he does after that is all in the line of work. ~Edward F. Croker</font></i><br> </font></td> </tr> <tr> <td width="479" height="130" valign="top" bordercolor="#000080" style="border-style: double; border-width: 5px; padding: 1px"><p>Evaluations are now available. To complete the evaluation packet, <a href="http://www.surveymonkey.com/s.aspx?sm=yucw0wu1q3O1I_2b18iRUtug_3d_3d">Click Here</a> The Password is: <strong>ffeval09</strong></p> <p>This evaluations will be available until March 20, 2009. Please complete before that date. </p></td> <td width="2" rowspan="4" valign="top"> <!-- MSCellType="empty" --> </td> <td width="199" rowspan="4" valign="top"> <table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%"> <!-- MSCellFormattingTableID="1" --> <tr> <td bgcolor="#FF0000" colspan="3" height="2"> <img alt="" width="1" height="2" src="../images/MsSpacer.gif"></td> </tr> <tr> <td bgcolor="#FF0000" width="2"> <img alt="" width="2" height="1" src="../images/MsSpacer.gif"></td> <td valign="top" width="100%"> <!-- MSCellFormattingType="content" --> <p align="center" style="margin-top: 0; margin-bottom: 0"> <font size="4" color="#FF0000">News and such...</font></p> <hr> <p align="center" style="margin-top: 0; margin-bottom: 0"> <font size="4">Don't forget to complete your evaluations by March 20, 2009 </font></p> <hr> <p align="center" style="margin-top: 0; margin-bottom: 0"> </p> <p align="center" style="margin-top: 0; margin-bottom: 0"> <font size="4">We are starting strong with the Relay for Life with several ideas in the planning process. We have set a goal of $3,000 this year and we need as much participation as possible to help us reach that goal. </font></p> <p align="center" style="margin-top: 0; margin-bottom: 0"> </p> <hr> <p align="center" style="margin-top: 0; margin-bottom: 0"> </p> <p></td> <td bgcolor="#FF0000" height="100%" width="2"> <img alt="" width="2" height="1" src="../images/MsSpacer.gif"></td> </tr> <tr> <td bgcolor="#FF0000" colspan="3" height="2"> <img alt="" width="1" height="2" src="../images/MsSpacer.gif"></td> </tr> </table> </td> </tr> <tr> <td height="22" valign="top" bgcolor="#FFFFFF"> </td> </tr> <tr> <td height="40" bordercolor="#FF0000" bgcolor="#FFFF00" style="border-style: solid; border-width: 1px; padding-top: 1px; padding-bottom: 1px"> <p align="center"><font size="5" color="#800000"><b>Training Info...</b></font></td> </tr> <tr> <td height="224" valign="top" bordercolor="#FF0000" bgcolor="#C0C0C0" style="border-style: solid; border-width: 1px; padding-top: 1px; padding-bottom: 1px"> <blockquote> <p align="left">Training is progressing. Brian has implemented a new training calendar, and we have had decent turn out each Thursday. All officers are encouraged to attend each training session as this shows leadership and committment to the firefighters. </p> <p align="left"><a href="officer_memberfiles.htm">Officer Memberfiles </a></p> <p align="left"> </p> </blockquote> </td> </tr> <tr> <td height="19"> </td> <td> </td> <td> </td> </tr> <tr> <td height="42" colspan="3" align="center" valign="top"><a href="logout.php">Log Out of Officers Area </a></td> </tr> <tr> <td height="68"> </td> <td> </td> <td> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/155242-solved-displaying-table-info-based-on-session-variable/ Share on other sites More sharing options...
radi8 Posted April 22, 2009 Share Posted April 22, 2009 Well, my first thoughts on the highlighted section of code is that the database field for first name and last name is probably not the names passed in from the POST elements. in the database, what are the column names being retrieved? In mine, I have: userName fName lName accessLevel password (encrypted) etc... so if you are doing a: <?PHP /* $firstname = $_POST['firstname'] ; $lastname = $_POST['lastname'] ; $password=$_POST['password']; */ $user = $_POST['username'] ; $sql = "SELECT * FROM `officers` WHERE userName = '".$user."'";// and password=md5($password) $result = mysql_query($sql) ; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $dbfname = $row['fName'] ; // ALT usage by column position: $row[1] $dblname = $row['lName'] ; // ALT usage by column position: $row[2] $dbuser = $row['username'] ; // ALT usage by column position: $row[0] } echo "$dbfname $dblname" ; ?> This should yield the proper output Link to comment https://forums.phpfreaks.com/topic/155242-solved-displaying-table-info-based-on-session-variable/#findComment-816774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.