smithmr8 Posted February 17, 2008 Share Posted February 17, 2008 Hello Again, I am trying to get this script to show a specific person's details, ie Username, when their ID is put at the end of a URL. E.g. Lets say someone with ID:3 has the username "Fred". When the page, view.php?id=3 is shown, it should echo that username, 'Fred'. I've tried to do it, but cant seen to remember how to use the id used in the url and assign it to a variable. This is what I've got so far, which isn't working. <?php include('header.php') ?> <?php if($_GET['id'] == $id){ $information="SELECT * FROM users WHERE ID = $id"; $result_information = mysql_query($information); $view=mysql_fetch_array($result_information); echo $view['username']; } else { echo "Error"; echo $id; } ?> <?php include('footer.php') ?> Quote Link to comment https://forums.phpfreaks.com/topic/91582-_get-question/ Share on other sites More sharing options...
Lumio Posted February 17, 2008 Share Posted February 17, 2008 what about <?php if (isset($_GET['id'] && is_numeric($_GET['id'])) { //code } Quote Link to comment https://forums.phpfreaks.com/topic/91582-_get-question/#findComment-469093 Share on other sites More sharing options...
smithmr8 Posted February 17, 2008 Author Share Posted February 17, 2008 But, how do I assign that numeric ID to a variable ? Quote Link to comment https://forums.phpfreaks.com/topic/91582-_get-question/#findComment-469098 Share on other sites More sharing options...
wildteen88 Posted February 17, 2008 Share Posted February 17, 2008 simpley add $id = $_GET['id']; in between the parenthesis for Lumios code, eg: if (isset($_GET['id'] && is_numeric($_GET['id'])) { $id = $_GET['id']; } else { die('Invalid id'); // display error if id is not numeric; } Quote Link to comment https://forums.phpfreaks.com/topic/91582-_get-question/#findComment-469104 Share on other sites More sharing options...
smithmr8 Posted February 17, 2008 Author Share Posted February 17, 2008 Oh, right. I've tried that, but it doesn't seem to be working. I cant give any error details as my host doesn't have them enabled for some reason. I now have this.. if (isset($_GET['id'] && is_numeric($_GET['id'])) { $id = $_GET['id']; $information="SELECT * FROM users WHERE ID = $id"; $result_information = mysql_query($information); $view=mysql_fetch_array($result_information); echo $view['username']; } else { echo "Error"; echo $id; } Quote Link to comment https://forums.phpfreaks.com/topic/91582-_get-question/#findComment-469107 Share on other sites More sharing options...
tmyonline Posted February 17, 2008 Share Posted February 17, 2008 Did you establish a connection to the database ? Quote Link to comment https://forums.phpfreaks.com/topic/91582-_get-question/#findComment-469112 Share on other sites More sharing options...
smithmr8 Posted February 17, 2008 Author Share Posted February 17, 2008 Its always connected to the database. I know the connections are working, as the rest of the site work fine. Its something to do with the (isset($_GET['id'] && is_numeric($_GET['id'])) . Quote Link to comment https://forums.phpfreaks.com/topic/91582-_get-question/#findComment-469116 Share on other sites More sharing options...
Stooney Posted February 17, 2008 Share Posted February 17, 2008 try this <?php if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id']; $information="SELECT * FROM users WHERE ID = $id"; $result_information = mysql_query($information); $view=mysql_fetch_assoc($result_information); echo $view['username']; } else { echo "Error"; echo $id; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/91582-_get-question/#findComment-469118 Share on other sites More sharing options...
smithmr8 Posted February 17, 2008 Author Share Posted February 17, 2008 Yay. That worked. Thanks alot. . Much Appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/91582-_get-question/#findComment-469121 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.