undertaker Posted April 30, 2011 Share Posted April 30, 2011 How to achieve and use .php?id= ? I cant find any explanation on google. If i type that in, i only find all the pages that use that. I assume this is ment to achieve different data on same page. for example .php?id=20 , .php?id=something thanks Quote Link to comment https://forums.phpfreaks.com/topic/235225-phpid/ Share on other sites More sharing options...
wildteen88 Posted April 30, 2011 Share Posted April 30, 2011 The text that comes after the question make in the url is referred to as the query string. It is up to you what you set in the query string in order for your php script to function. For example you're making a news script. You may code this script so it requires an id variable to be passed in the query string to grab a news entry within a database that is associated with that id. Quote Link to comment https://forums.phpfreaks.com/topic/235225-phpid/#findComment-1208811 Share on other sites More sharing options...
QuickOldCar Posted April 30, 2011 Share Posted April 30, 2011 This would be achieved by using GET in a form or simply assigning a variable to a GET value from the address bar url. With or without a form does not matter. Try changing the value in just the url to see. A simple example: <?php $id = mysql_real_escape_string($_GET['id']); ?> <form name="input" action="" method="get"> ID: <input type="text" name="id" value="<?php echo $id;?>"/> <input type="submit" value="Submit" /> </form> <?php if(!isset($_GET['id']) OR $id == "") { echo "Please insert a value"; } else { echo "The id is $id <br />"; } ?> For some tutorials on forms along with GET,POST and so on. http://www.w3schools.com/html/html_forms.asp http://www.tizag.com/phpT/postget.php Quote Link to comment https://forums.phpfreaks.com/topic/235225-phpid/#findComment-1208828 Share on other sites More sharing options...
Drongo_III Posted April 30, 2011 Share Posted April 30, 2011 Hi Undertaker I'm new to php and I came across this same thing a few weeks ago. The explanation of it is well covered in the post above. One thing worth noting (if you don't already know) is that you can access query strings by using the $GET array. Just thought that was worth mentioning as it wasn't obvious to me...or maybe I'm just slow! Drongo Quote Link to comment https://forums.phpfreaks.com/topic/235225-phpid/#findComment-1208829 Share on other sites More sharing options...
undertaker Posted May 1, 2011 Author Share Posted May 1, 2011 awesome Thanks everyone for help Now i finally know Quote Link to comment https://forums.phpfreaks.com/topic/235225-phpid/#findComment-1209022 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.