By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,722 Members | 1,874 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,722 IT Pros & Developers. It's quick & easy.

caputuring the var on address bar

ddtpmyra
100+
P: 333
I have 1st php script where i assigned the value 'id' on the next page where this time I use html coding. My question is how can you capture the id number (see below quote) on html code to pass it to the next page with php script this time?

http://myrab.ddtp.org/add_reviewer.php?id=1
Oct 9 '08 #1
Share this Question
Share on Google+
14 Replies


acoder
Expert Mod 15k+
P: 16,027
This is not possible with HTML. You can either use PHP or JavaScript (if PHP isn't an option) to retrieve the value.
Oct 9 '08 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
I fully agree with acoder. HTML/CSS are only for the display of the web page and not able to process values passed between pages. That is what scripting languages, such as PHP and Javascript, are for. You will need to use one of them to capture the information passed.

Regards,

Jeff
Oct 9 '08 #3

Markus
Expert 5K+
P: 6,050
Moving to PHP forum.
Oct 9 '08 #4

Markus
Expert 5K+
P: 6,050
You can access variables in the url by $_GET['key']. In your case it would be $_GET['id']

Markus.
Oct 9 '08 #5

P: 9
I feel kind of confused with your question, so I'm going to answer how to pass the variable with and without PHP.

With PHP:

use the $_REQUEST array to get the information defined, in your case, it's $_REQUEST["id"]

WIthout PHP:
You can use javascript to parse the URL, var url = window.location and you'd get the url. You can parse it and then use the variable stored in JS or forward to another page.
Oct 9 '08 #6

Atli
Expert 5K+
P: 5,058
Just to clarify.

The passing of variables via the URL, as you demonstrated, is referred to as the HTTP GET protocol.

In PHP, you get these sort of variables via the $_GET super-global, like Markus demonstrated.

There are other HTTP protocols, such as the POST protocol, which PHP makes available via the $_POST super-global.

Both of these, as well as all cookies, are combined into the $_REQUEST super-global. As a result, when you fetch the variable "id" from the $_REQUEST super-global, that element can be coming from any of these protocols.

Using the $_GET, $_POST or $_COOKIES super-globals is generally better than using the $_REQUEST super-global, because that way you know exactly where you data is coming from.
Oct 9 '08 #7

Markus
Expert 5K+
P: 6,050
Using the $_GET, $_POST or $_COOKIES super-globals is generally better than using the $_REQUEST super-global, because that way you know exactly where you data is coming from.
I wonder how $_REQUEST would act if it found 'id' in GET and POST?
Oct 9 '08 #8

ddtpmyra
100+
P: 333
Thanks for all your help :)
I just use $POST
Oct 9 '08 #9

Atli
Expert 5K+
P: 5,058
I wonder how $_REQUEST would act if it found 'id' in GET and POST?
To quote the default PHP.ini configuration file. (PHP 5.2.6)
; This directive describes the order in which PHP registers GET, POST, Cookie,
; Environment and Built-in variables (G, P, C, E & S respectively, often
; referred to as EGPCS or GPC). Registration is done from left to right, newer
; values override older values.
variables_order = "EGPCS"
So basically, Session variables override all other values. Cookies are second, then POST, GET and finally Environment.

So in your situation, you would get the ID from POST.
Oct 10 '08 #10

acoder
Expert Mod 15k+
P: 16,027
With PHP:

use the $_REQUEST array to get the information defined, in your case, it's $_REQUEST["id"]
Atli's already responded to this - it's better to use a specific super-global rather than $_REQUEST.

WIthout PHP:
You can use javascript to parse the URL, var url = window.location and you'd get the url. You can parse it and then use the variable stored in JS or forward to another page.
You can use something more specific here too - window.location.search - see link.
Oct 10 '08 #11

acoder
Expert Mod 15k+
P: 16,027
Thanks for all your help :)
I just use $POST
Shouldn't that be $_GET ?
Oct 10 '08 #12

ddtpmyra
100+
P: 333
Here I go again....

now it's not working and it's weird maybe you can find what's wrong in between.


here's my 1st page where my submit button is..
[PHP]<input name="id" type="hidden" id="id" value="<?id=$_GET['id']?>">[/PHP]

here's my insert SQL
[PHP]$id=$_POST['id'];
etc....

$sql="INSERT INTO $tbl_name(topic, detail, name, email, datetime, cmrid)
VALUES('$topic', '$detail', '$name', '$email', '$datetime','$id')";
$result=mysql_query($sql) or die(mysql_error());[/PHP]

and here's my 2nd page where I got the error message
myraYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id']?>')' at line 2
Oct 24 '08 #13

Atli
Expert 5K+
P: 5,058
Try replacing:
Expand|Select|Wrap|Line Numbers
  1. <?id=$_GET['id']?>
  2.  
with:
Expand|Select|Wrap|Line Numbers
  1. <?php echo $_GET['id']; ?>
  2.  
The former uses the short-tags PHP block (incorrectly by the way), which is not enabled in PHP by default, and should therefore be avoided.
If that is the case, then, rather than printing the result of the PHP code, it would simply display the PHP code, which would mean that the PHP code would be passed into your query, obviously causing an error.
Oct 24 '08 #14

ddtpmyra
100+
P: 333
Your are right Atli thanks!
Oct 24 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.