jdrasq Posted August 5, 2007 Share Posted August 5, 2007 Hello, I have a database set up which is displaying a single piece of data by looking up the id field which I have entered in, but I have seen on some pages that it is possible to set up a page called, for example, page.php?ID=1 which displays the data from where ID = 1, but I cannot find a tutorial that explains how to do this, could anybody help? Thank you, JDRasq Quote Link to comment https://forums.phpfreaks.com/topic/63445-displaying-data-from-mysql-on-a-php-page-pagephpid/ Share on other sites More sharing options...
wildteen88 Posted August 5, 2007 Share Posted August 5, 2007 You use $_GET to get url parameters from the url, eg mysite.com?page.php?id=1234 to get the id parameter from the url you'd use $_GET['id']. You'd then use $_GET['id'] within your query: // check if id is set and that it only consists of numbers. // You should always validate data before using it if(isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id']; $sql = "SELECT * from pages_table WHERE page_id='$id'"; $result = mysql_query($sql); // rest of code here for displaying the page data from the database. } Quote Link to comment https://forums.phpfreaks.com/topic/63445-displaying-data-from-mysql-on-a-php-page-pagephpid/#findComment-316277 Share on other sites More sharing options...
mwookie Posted August 6, 2007 Share Posted August 6, 2007 One thing to remember is to always validate what come in before making the query. Don't assume that people will only click the links they see. For example what are you going to do if they submit an id beyond those in the database. Maybe common sense to some, but I have made my fair share of mistake this way and sometimes someone gets into what they shouldn't. ________________ "You cannot escape the responsibility of tomorrow by evading it today." Abraham Lincoln New Mexico Web Design – Projects (Search food stock images – Make $$ selling photos) Quote Link to comment https://forums.phpfreaks.com/topic/63445-displaying-data-from-mysql-on-a-php-page-pagephpid/#findComment-316995 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.