473,378 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

caputuring the var on address bar

ddtpmyra
333 100+
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
14 2398
acoder
16,027 Expert Mod 8TB
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
3,509 Expert Mod 2GB
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
6,050 Expert 4TB
Moving to PHP forum.
Oct 9 '08 #4
Markus
6,050 Expert 4TB
You can access variables in the url by $_GET['key']. In your case it would be $_GET['id']

Markus.
Oct 9 '08 #5
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
5,058 Expert 4TB
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
6,050 Expert 4TB
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
333 100+
Thanks for all your help :)
I just use $POST
Oct 9 '08 #9
Atli
5,058 Expert 4TB
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
16,027 Expert Mod 8TB
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
16,027 Expert Mod 8TB
Thanks for all your help :)
I just use $POST
Shouldn't that be $_GET ?
Oct 10 '08 #12
ddtpmyra
333 100+
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
5,058 Expert 4TB
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
333 100+
Your are right Atli thanks!
Oct 24 '08 #15

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

Similar topics

21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
2
by: jason | last post by:
Hello and Good day. There's a site I want to link to passing info I collect without having to re-enter the data on that's sites input form. I know this is not always possible, but in this case...
8
by: YAN | last post by:
Hi, I want to get the mac address from a machine, which i have the IP address of that machine, how can i do that? I know how to get the mac address of the local machine from the following code: ...
12
by: johny smith | last post by:
I am trying to figure out a way to print the address of what called a certain function once inside the function. I am assuming that this information is on the stack somewhere. But can someone...
7
by: Privacy Advocate | last post by:
//crossposted to: comp.lang.javascript, alt.comp.lang.javascript in an effort to get factual answers from JavaScript experts// Simply put; Is it possible to obtain the real (actual) IP address of...
33
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
5
by: Kevin Newman | last post by:
Does anyone know of any application (AJAX or other) that will display the appropriate address for for the selected (or detected) country? If not, does anyone know where I can find a list or...
4
by: andreas.w.h.k. :-\) | last post by:
How do I change the address location in the wsdl <wsdl:port name="SearchSoap12" binding="tns:SearchSoap12"> <soap12:address location="http://searchservices/engine/search.asmx" /> </wsdl:port> ...
1
by: Phoenix_ver10 | last post by:
I have a mailing list with multiple names going to the same addresses. I need one address with all the names for that address on it. I checked out the example on microsoft's site, but A: It doesn't...
4
by: karen.homersham | last post by:
Just working through Apress Pro ASP NET.2.0.E Commerce in C Sharp. I am having problems compiling the following: using System; using System.Collections.Generic; using System.Text; namespace...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.