joyza Posted October 5, 2011 Share Posted October 5, 2011 I currently have a project undergoing, however i need help integrating two scripts: Login script & Comment Script The checking if logged in part is this - if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) { header("location: access-denied.php"); exit(); } and i want it so that i can check if the user is logged in the comment script will use there first name from my mysql table of members. The field name in the table for first name is 'firstname' and my comment section script looks like this echo "<div class=\"commentbody\" id=\"$commentrow[0]\">\n <p class=\"postedby\">Posted by "; if($commentrow[3]){ echo "<a href=\"$commentrow[3]\">$commentrow[2]</a> "; } else { echo "$commentrow[2] "; } echo "</p> \n <p>$commentbb</p>\n\n</div>"; } echo "</div>"; } Please someone help me, its driving me crazy. Any more info needed just ask many thanks in advance!! Quote Link to comment https://forums.phpfreaks.com/topic/248449-integration/ Share on other sites More sharing options...
the182guy Posted October 5, 2011 Share Posted October 5, 2011 You're using this to access data from the record set: $commentrow[3] That is very unreadable, when dealing with a set of fields as you are, use the field name like $commentrow['firstname']. Be sure to use mysql_fetch_assoc() not fetch_row() or fetch_array(). Also, it's a good idea to store small pieces of user information in the session such as first name so you can quickly access those details without having to query the db. Take for example a "Welcome John" sort of message shown on all pages. Quote Link to comment https://forums.phpfreaks.com/topic/248449-integration/#findComment-1275914 Share on other sites More sharing options...
joyza Posted October 5, 2011 Author Share Posted October 5, 2011 i have got the $commentrow[3] as you said in parts just found it easier in terms of form layout however I can't remember how to do the 'Welcome ' user variable stuff any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/248449-integration/#findComment-1276235 Share on other sites More sharing options...
joyza Posted October 5, 2011 Author Share Posted October 5, 2011 $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; Thats the stuff that is used to check if the login was successful and the variables used. How would i use that to print out "Welcome username". And also how would i make it so that when the guest has logged in, on the comment script it would change the name textfield to the username, could i use an if statement or what?? All help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/248449-integration/#findComment-1276238 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.