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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.