derekbelcher Posted March 13, 2009 Share Posted March 13, 2009 I have a php login in place on my web application. On the page you go to when you login successfully, I want to display the first name (stored in the database) that is associated with that user that is logged in. Below is the code on the page. At line 20 I have attempted something but it didn't work: <? session_start(); if(!session_is_registered(myusername)){ header("location:officerLogin.php"); } ?> <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, <?php $_SESSION['myusername'] ?> </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"> </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> Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/ Share on other sites More sharing options...
jackpf Posted March 13, 2009 Share Posted March 13, 2009 Yeah, you're not actually echoing the session variable. If you want to send something to the page you have to echo it... Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784026 Share on other sites More sharing options...
ionik Posted March 13, 2009 Share Posted March 13, 2009 <?= $_SESSION['myusername'] ?> // OR <?php echo $_SESSION['myusername']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784029 Share on other sites More sharing options...
derekbelcher Posted March 13, 2009 Author Share Posted March 13, 2009 Thanks the echo worked great. Now I have one more question. There is a first name associated with each username stored in the database. How can I display the name associated with myusername? I tried to echo the variable, but I don't think it is looking at the database, it is just pulling the username from the login page. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784033 Share on other sites More sharing options...
jackpf Posted March 13, 2009 Share Posted March 13, 2009 Yeah, you'll need to do something like this- mysql_query("SELECT * FROM table WHERE username='$username'"); $fetch = mysql_fetch_array($sql); $name = $fetch['name_of_person']; echo $name; Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784035 Share on other sites More sharing options...
ionik Posted March 13, 2009 Share Posted March 13, 2009 you will need to pull the information from your database. This can be done by using whichever Database you are using if you are using MySQL Database take a look here http://php.net/mysqli Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784037 Share on other sites More sharing options...
derekbelcher Posted March 13, 2009 Author Share Posted March 13, 2009 I got this below when I inserted the code, did I miss something? Sorry, I am just beginning to learn this stuff. Welcome, Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/athens/public_html/Officers Area/officer_index.php on line 20 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/athens/public_html/Officers Area/officer_index.php on line 20 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/athens/public_html/Officers Area/officer_index.php on line 21 Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784041 Share on other sites More sharing options...
jackpf Posted March 13, 2009 Share Posted March 13, 2009 Yeah, you do actually need to connect to your mysql database first...I just assumed you knew that. Why don't you google a php-mysql tutorial or something...? Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784043 Share on other sites More sharing options...
derekbelcher Posted March 13, 2009 Author Share Posted March 13, 2009 ok, i connected to the database, now I get an error related to the mysql_fetch_array($sql); Welcome, Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/athens/public_html/Officers Area/officer_index.php on line 32 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784045 Share on other sites More sharing options...
premiso Posted March 13, 2009 Share Posted March 13, 2009 $sql = mysql_query("SELECT * FROM table WHERE username='$username'"); $fetch = mysql_fetch_assoc($sql); $name = $fetch['name_of_person']; echo $name; Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784047 Share on other sites More sharing options...
derekbelcher Posted March 13, 2009 Author Share Posted March 13, 2009 So close, but I am still unclear as to what I am supposed to do to fix the error related to the mysql_fetch_assoc. I tried to google it, but it just confuses me. Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784052 Share on other sites More sharing options...
premiso Posted March 13, 2009 Share Posted March 13, 2009 You did change "table" to your actual table name. The above is a rough example. If this still confuses you, go find a MySQL/PHP Tutorial as suggested earlier, as it shows you have never tried one before. Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784061 Share on other sites More sharing options...
derekbelcher Posted March 13, 2009 Author Share Posted March 13, 2009 Yeah, I had the table name right. I know it was just a rough example. I have to be honest, I have learned more from this forum than all the tutorials I have tried. Thanks for your help. Maybe you can help explain what parts of the example need to be changed to be specific to my site. That would help. I knew the table thing because I had used that part of the code elsewhere. The column name I am trying to pull is called firstname. does that help? Quote Link to comment https://forums.phpfreaks.com/topic/149297-solved-need-a-little-help/#findComment-784065 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.