473,378 Members | 1,346 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.

Passing Variables

First off, yes, I understand the crapload of tutorials out there, (well,
rather, I understand there /are/ a crapload of tutorials out there), the
problem is my comprehension.

I'm trying to pass variables, and can do so just fine with a URL, and $_GET.
What I would like to learn, and be very adept at using is the Form functions
and how you pass through that.

The problem in my comprehending this, is how does the original page know how
to post the data to the new page? Or do you create the form on the original
page, and somehow, magically, the new page can read from it?

Can someone break it down into the most basic steps, remembering that i'm a
2-week newbie? :)

Sometimes, all we need is a little one on one attention.

-Thank you,
Humbly,
Khai
Nov 22 '05 #1
7 2758
>I'm trying to pass variables, and can do so just fine with a URL, and $_GET.
What I would like to learn, and be very adept at using is the Form functions
and how you pass through that.

The problem in my comprehending this, is how does the original page know how
to post the data to the new page? Or do you create the form on the original
page, and somehow, magically, the new page can read from it?


Yes -- you create the form on the original page and specify where the
form should be submitted. Suppose on page1.php you had something like
this:

<form action="page2.php" method="post">
<input type="text" name="foo"/>
<input type="submit" name="submit" value="Submit"/>
</form>

So when someone fills in this form and hits submit, the browser will
post the form data to page2.php. On page2.php you can access foo and
submit through the $_POST superglobal (in exactly the same way you get
to the GET variables). Also note that there is nothing that prevents
you from putting the current page into the "action" attribute -- that
is, it is perfectly valid (and often quite useful) to have a page with
a form post to itself.

Nov 22 '05 #2
So, can I post variables to another page without user interaction?

Say, I have 3 different pages linked off the primary page, and each link
needs the same or different information for different purposes.

Can I programmatically tell it which vars to pass, without having someone
click on something other than the <a href>?

*starting to understand*
...i think.

-Khai

----- Original Message -----
From: "ZeldorBlat" <ze********@gmail.com>
Newsgroups: comp.lang.php
Sent: Thursday, November 17, 2005 9:30 AM
Subject: Re: Passing Variables

I'm trying to pass variables, and can do so just fine with a URL, and $_GET.What I would like to learn, and be very adept at using is the Form functionsand how you pass through that.

The problem in my comprehending this, is how does the original page know howto post the data to the new page? Or do you create the form on the originalpage, and somehow, magically, the new page can read from it?


Yes -- you create the form on the original page and specify where the
form should be submitted. Suppose on page1.php you had something like
this:

<form action="page2.php" method="post">
<input type="text" name="foo"/>
<input type="submit" name="submit" value="Submit"/>
</form>

So when someone fills in this form and hits submit, the browser will
post the form data to page2.php. On page2.php you can access foo and
submit through the $_POST superglobal (in exactly the same way you get
to the GET variables). Also note that there is nothing that prevents
you from putting the current page into the "action" attribute -- that
is, it is perfectly valid (and often quite useful) to have a page with
a form post to itself.

Nov 22 '05 #3
>So, can I post variables to another page without user interaction?

Say, I have 3 different pages linked off the primary page, and each link
needs the same or different information for different purposes.

Can I programmatically tell it which vars to pass, without having someone
click on something other than the <a href>?


How are you going to get the user's browser to go to a different page
without them clicking on something? You just said that the 3 pages are
"linked" off the main page -- I read that as meaning that there are
hyperlinks or forms that post to those pages...

Nov 22 '05 #4
ZeldorBlat said:
You just said that the 3 pages are
"linked" off the main page -- I read that as meaning that there are
hyperlinks or forms that post to those pages...

Yes, that's correct. What I mean to ask is, do I have to use a form button
or something for the action to trigger? Or can I create the hyperlink to
run some function that posts those vars to whichever page I send to the
function?

function postmyvars (strPageName) {

}

or something-ish. I've yet to actually create any user-defined functions..
Nov 22 '05 #5
>Yes, that's correct. What I mean to ask is, do I have to use a form button
or something for the action to trigger? Or can I create the hyperlink to
run some function that posts those vars to whichever page I send to the
function?


PHP operates on the server-side. That is: client makes request,
webserver/PHP process request, webserver sends output to browser. If
you want things to happen on the client-side in between (i.e. redirect
to a different page when the user rolls his mouse over some image) then
you need something like JavaScript.

Nov 22 '05 #6
Khai wrote:
ZeldorBlat said:
You just said that the 3 pages are
"linked" off the main page -- I read that as meaning that there are
hyperlinks or forms that post to those pages...
Yes, that's correct. What I mean to ask is, do I have to use a form button
or something for the action to trigger? Or can I create the hyperlink to
run some function that posts those vars to whichever page I send to the
function?

You can put the variable in a hyper link.
http://site.com/mypage.php?cit=cinncinati

In mypage.php , $_GET will be an array with a member named 'city' with a
value of 'cincinatti';
$mycity=$_GET[city];
function postmyvars (strPageName) {

}

or something-ish. I've yet to actually create any user-defined functions..

Nov 22 '05 #7
>From my understanding the variables are passed along from a form depending on
the "method" in your HTML code. If you use the "GET" method, the form adds the
variable to the URL (e.g. http://www.domain.com/phpscript?var1=1+var2=2 ) and
would access them in PHP with the $_GET variables.
Yes.
If the form uses the "POST" method though, the variable are passed along more
transparently, so you don't see them on the URL, and can get the using the
$_POST variables.


Also true. It's also worth noting that this is no way makes POST more
secure than GET.

Nov 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Amr Mostafa | last post by:
Hello :) I'm trying to write a script that deals with a web service. I'm using NuSoap class. my question is : Can I pass some variables By Reference to the web service and get the result back...
4
by: Jason Us | last post by:
Does anyone have experience with passing variables from an ASP page to a JSP page. The way it currently works in passing the SSN in the URL. This cannot be good. I thought that storing a...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: Jack | last post by:
Hi, I need to pass multple variables in a link in order to go to a asp page with the two varables. The following are the values of the variables using response.write: <%'Response.Write Mypage...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
20
by: Gregory Piñero | last post by:
Hey guys, would someone mind giving me a quick rundown of how references work in Python when passing arguments into functions? The code below should highlight my specific confusion: <code> ...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
3
by: Lee | last post by:
Hi All How can I pass options from one webpage into another webpage. When the user clicks on the hyperlink I want them to be go to the next page but I need to pass in a number that the next...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
6
BezerkRogue
by: BezerkRogue | last post by:
This is the most fundamental action I am sure, but I can't seem to make it happen. I am familiar with passing variables in ASP. But that doesn't seem to be the preferred method in .NET. I have...
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: 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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.