473,788 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pass variables throught the URL into my PHP page?

4 New Member
how do i get the query from an url to change variables in my website

for example my website is called www.example.com

so the query would be www.example.com?qwerty

and i want a link in my site to change as the query does

so a link in my site would change to www.thescripts.com/qwerty

is there away i can do this please let me know i am very desperate to find out

thanks in advance!
Nov 2 '07 #1
10 2121
jx2
228 New Member
try:
[php]
echo $_GET['variableName'];
echo $GLOBALS['QUERY_STRING']; //WHOLE THING
[/PHP]

REGARDS
JX2
Nov 2 '07 #2
Atli
5,058 Recognized Expert Expert
Hi mcphearson. Welcome to TSDN!

You can add variables, via the GET protocol, to the URL and fetch them in your code.

If you want to pass a value for user ID, you might have an URL that looks like this:
Expand|Select|Wrap|Line Numbers
  1. www.example.com/page.php?userID=1
  2.  
Then you could fetch this variable via the $_GET super-global in your PHP code:
Expand|Select|Wrap|Line Numbers
  1. echo "User ID: ". $_GET['userID'];
  2.  
You can have more than one variable, just separate them with a & sign:
Expand|Select|Wrap|Line Numbers
  1. www.example.com/page.php?userID=1&userName=yourName
  2.  
P.S.
I've edited the thread's title. Please take a look at our Posting Guidelines for tips on how to create good thread titles.
Nov 2 '07 #3
mcphearson2345
4 New Member
thanks very much for your help

although im still confused

im not that great with php

how would i include that code in to my site

would i put that code in the link that i want to change

for example

<a href="http://www.domain.com/echo "User ID: ". $_GET['userID'];">

so will the link change from the / onwards.. to the query in the Url??


thanks in

Ps im using dreamweaver if that makes any difference
Nov 3 '07 #4
jx2
228 New Member
<a href="http://www.domain.com/echo "User ID: ". $_GET['userID'];">
no llike that :/
you have two choices
[php]
<html>
<body>
<a href="<?php echo "$PHP_SELF?user ID=$_GET['userID']"; ?>" >link</a>
</body>
</html>
[/php]
or you can echo everything :-)
[php]
<?php
echo "<html>
<body>
<a href='$PHP_SELF ?userID=$_GET['userID']'>link</a>
</body>
</html>
";
[/php]
regards
jx2
Nov 3 '07 #5
mcphearson2345
4 New Member
Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /data/members/paid/b/i/binco.co.uk/htdocs/splashpage/apple.php on line 237

that is the message i keep getting

i really dont know what im doing wrong...

i know you guys have much better things to do and i dont want to put you out!

is there a way i can send you all my html code and you coud edit it then send it back??

pleaes let me know

and thanks very much for all your help so far
Nov 3 '07 #6
post
17 New Member
Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /data/members/paid/b/i/binco.co.uk/htdocs/splashpage/apple.php on line 237

that is the message i keep getting

i really dont know what im doing wrong...

i know you guys have much better things to do and i dont want to put you out!

is there a way i can send you all my html code and you coud edit it then send it back??

pleaes let me know

and thanks very much for all your help so far
I don't know which example you picked but I fixed both of them so you can use either one.
[php]
<?php
echo "<html>
<body>
<a href='$PHP_SELF ?userID=$_GET[userID]'>link</a>
</body>
</html>
";
?>
[/php]
[html]
<html>
<body>
<a href="<?php echo "$PHP_SELF?user ID=$_GET[userID]"; ?>" >link</a>
</body>
</html>
[/html]
Nov 4 '07 #7
vijcbe
16 New Member
One can use $_GET or $_REQUEST method to pass a variable and the suggestions given by our forum friends are very correct. But, I insist to store the variable in a session variable and make the session alive until you are done with your job. Once your job is done, you can unset the session variable. You cannot send data through URL, which you wanted to be encrypted, since, data sent are visible in the address bar. I reckon this piece of information will help you.
VJ
Nov 4 '07 #8
Markus
6,050 Recognized Expert Expert
I think you're all missing his questions.

He asked how to change

Expand|Select|Wrap|Line Numbers
  1. www.example.com?username
  2.  
to
Expand|Select|Wrap|Line Numbers
  1. www.example.com/username
  2.  
I have an inkling he's likely to be talking about virtual hosting, is it? You know how MySpace has www.myawfulspac e.com/usersprofile

I believe this would be done through .htaccess, but i really have no idea.

Also, i don't even know whether this is what he asked ¬_¬ It just seemed no one took into consideration the /qwerty he talked about.

If anyone knows any good tutorials on virtual hosting(not sure if it is that) could you post them please?

Thanks :)
Nov 4 '07 #9
mcphearson2345
4 New Member
Ive done it

id like to thankyou sooo much. you have made my day. i used some of the code that was posted and i had to alter it a little, but it works perfect.

thankyou once again

i will be recomending this site to everyone and i will sure be back next time i need help
Nov 4 '07 #10

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

Similar topics

2
4606
by: Matt | last post by:
How to pass data back and forth between ASP and JSP page? Let's say I have Java objects, how to pass the data back to ASP page?? Or ASP has data, how to pass the data to JSP page?? Please advise. Thanks!
5
2336
by: eagletender | last post by:
I am simply trying to pass a variable to another page. I know my second page can do Request("str") to retrieve that variable, but how do I pass it in the first place? I tried Server.Execute("P2.asp?str="hello") but I get errors. I tried Response.Redirect("P2.asp?str="hello") but the variable is empty I tried setting variables like you would in VB: str="hello" Server.Execute("P2.asp")
12
1801
by: Casey | last post by:
Yeah, I know this question was asked by someone elselike 2 weeks ago. But I need some additional help. I have a program I'm developing, and multiple different forms will be opened. For now though, I just have two forms. One is the main window, and the other sets some preferences like names, and email addresses. When someone opens this window, and enters values on this page, I'd like it to set the values of public variables on the main...
1
2703
by: aruizdeinfante | last post by:
Hello I'm using a COM control in VC++, and the way to pass a picture to the control is throught this function void SetObjImage(LPDISPATCH ObjImage); I have found the way to pass this parameter creating an image throught CBitmap and CPictureHolder classes: CPictureHolder pictholder ; CBitmap bmpAux ;
4
1891
by: Israel Ordonez Jr | last post by:
Hi everybody, I am having a problem with an ASP.NET application i am working on. I new to ASP.NET so I'm not sure if I'm doing this right. I am working on a website that has an oil price listed throught several pages. In the global.asax file i have the following code. Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started
5
1925
by: adolf garlic | last post by:
Suggestions please for strategy to share values across app. Scenario: I have an asp.net app that uses some com components along with .net classes. Configuration settings for various things are held in an xml file to which the com has access. The xml file has different nodes for different instances (dev,uat1,uat2 etc..) there is a flag attribute to show current instance.
2
12364
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the users need not enter values in all the controls. they can leave the textbox blank, and select values from one drop down, or any other combinations. I am trying to pass values with the help of session variables. But I have multiple if else...
7
2238
by: Gladen Blackshield | last post by:
Hello All! Still very new to PHP and I was wondering about the easiest and simplest way to go about doing something for a project I am working on. I would simply like advice on what I'm asking so I can go and learn it myself through doing (best way for me). I am building a card game as a learning-project as it involves many (to most of the) things that I would like to learn to do with PHP.
12
11111
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.