Jump to content

php?id


undertaker

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/235225-phpid/#findComment-1208811
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/235225-phpid/#findComment-1208828
Share on other sites

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 :)

Link to comment
https://forums.phpfreaks.com/topic/235225-phpid/#findComment-1208829
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.