JackCode Posted January 6, 2014 Share Posted January 6, 2014 Hello, I am trying to achieve a universal link from one of my pages to my members page. Each user has an ID in my database and from my page I want it to link to their member page. How would I achieve this? Quote Link to comment Share on other sites More sharing options...
TinyI Posted January 6, 2014 Share Posted January 6, 2014 Hey, I'm assuming you mean when your user has logged in or click on a link, you want it to take them to their own specific member page? For the url, you'd need something like $url = 'member_page.php?member_id=${member_id}' Then, on the page, you'd need a $_REQUEST['member_id'] to grab that id and load their specific page. Hope this helps. If you need any clarification or if I assumed incorrectly, let me know. Quote Link to comment Share on other sites More sharing options...
iRoot121 Posted January 6, 2014 Share Posted January 6, 2014 I asume you want to have some sort of userlist, with a link to each user's profile. So, if this is the case, you can do something like this: Members.php: <?php $sql = mysql_query("SELECT * FROM `users` ORDER BY `id`"); if ($sql) { while ($info = mysql_fetch_array($sql)) { //Some userinfo here. //The link to the user his profile. echo '<a href="profile.php?user='.$info["id"].'">More info about this user.</a>'; } }else{ die(mysql_error()); } ?> Profile.php: if (!isset($_GET['user']) || $_GET['user'] == "") { echo 'Please insert a user to lookup..'; exit; }else{ $sql = mysql_query("SELECT * FROM users WHERE id='".$_GET['user']."'"); if (mysql_num_rows($sql)>0) { while ($info= mysql_fetch_array($sql)) { //User information to display. } }else{ echo 'This user isn\'t in our database!'; exit; } } Quote Link to comment Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 Hey, I'm assuming you mean when your user has logged in or click on a link, you want it to take them to their own specific member page? For the url, you'd need something like $url = 'member_page.php?member_id=${member_id}' Then, on the page, you'd need a $_REQUEST['member_id'] to grab that id and load their specific page. Hope this helps. If you need any clarification or if I assumed incorrectly, let me know. Thank you this is exactly what I needed. For a request do you just request for the ID in the page Im linking from? Quote Link to comment Share on other sites More sharing options...
TinyI Posted January 6, 2014 Share Posted January 6, 2014 Thank you this is exactly what I needed. For a request do you just request for the ID in the page Im linking from? The $_REQUEST is actually a combination of $_GET and $_POST. I was always taught to use $_REQUEST instead. You saw how the url was passed into the page? Well it works just from that. It takes the id from the url. By the way, please, please, please make sure to run filters on that string. As of PHP5, we have filter functions. So use the filter functions for integers and when you've cleaned & validated it, then let it touch the database. If you need any more help, let me know. I can go through it with you. Quote Link to comment 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.