February 21, 201412 yr Hello, I am looking to incorporate a database, which has been created within MySQL, into a website that I have built. I have managed to accomplish the basics of incorporating the DB to the site. They are communicating between each other. What I need help with is this; I want to be able to make it so that when someone logs into the site, using details saved within the database, they are brought to their account homepage ... this is where my troubles start ... I want to be able to populate certain parts of the site with information linking to them. I have all relationships set-up amongst the tables within the DB but I am struggling with incorporating it once a user has logged in. I understand the concept ... carrying over the username Primary Key and using that to link to everything else but I don't know how to carry this information over to another page and then use it to populate fields. Any help with this shall be very much appreciated. - MjA -
February 21, 201412 yr What I would do is create $_SESSION variables. On successful login you then set the variables you wish to 'carry around' the site such as $_SESSION['userid'] for the ID of the user. Then when a user goes to their 'account' page you can use the $_SESSION['userid'] as a reference to get the information you wish to display.
February 21, 201412 yr Forgot an example, sorry. On login if you set $_SESSION['username'] to the name of the logged in user and then try; <?php if(isset($_SESSION['username'])) { echo "Hello" . $_SESSION['username']; } else { echo "Hello Guest"; } ?>
February 21, 201412 yr Author Thank you for your response. I will look into this and try and get it working. It can sometimes be difficult when you understand what you want to achieve, and even understanding the concept, but not know how to word it. - MjA -
February 21, 201412 yr It can sometimes be difficult when you understand what you want to achieve, and even understanding the concept, but not know how to word it. Man, you hit the nail on the head there, it's called development
February 26, 201412 yr Author I just wanted to update this. I have managed to accomplish this thanks to your help. Very much appreciated. - MjA -
Create an account or sign in to comment