Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

PHP help for a Novice please

Explorer ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

Hi,

I am learning php, because I am working on a site that uses it, so, there is some syntax which I don't understand its function, so I thought if I post it here somebody may be able to tell me what it would do.....

A page has a form on it, the form begins with this
<?php $ref = $_GET['ref'];

then has the form tag with action="details_process.php?ref='.$ref.

now, the bit i'm not understanding what it does is the $ref = $_GET['ref']; and the ref='.$ref. at the end of the for action.

I appreciate this is taken out of the page so may make no sense, but if it is a standard function could somebody please tell me what it is?

Many many thanks in advance

that form action is set to go to a process.php page
TOPICS
Server side applications

Views

801
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 29, 2007 Nov 29, 2007
Well, the PHP function $_GET parses the URL for any variables, and is a
different entity entirely from the form method of "GET".

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"simbull" <webforumsuser@macromedia.com> wrote in message
news:fimnr2$j2h$1@forums.macromedia.com...
> ...

Votes

Translate
LEGEND ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

That's just a way of passing a variable to a page. Let's assume that the
form page is loaded using a URL like this -

http://www.example.com/yourformpage.php?ref=whatever

When the form page loads, it parses the ref variable from the link, so now
$ref has the value "whatever".

The form's action would create a URL like this -

http://www.example.com/details_process.php?ref=whatever

so that when the form is processed by details_process.php, that process page
can act according to the value of the $ref variable, carried through from
the page calling the form, to the form, then to the page processing the
form.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"simbull" <webforumsuser@macromedia.com> wrote in message
news:fimjjr$eep$1@forums.macromedia.com...
> Hi,
>
> I am learning php, because I am working on a site that uses it, so, there
> is
> some syntax which I don't understand its function, so I thought if I post
> it
> here somebody may be able to tell me what it would do.....
>
> A page has a form on it, the form begins with this
> <?php $ref = $_GET['ref'];
>
> then has the form tag with action="details_process.php?ref='.$ref.
>
> now, the bit i'm not understanding what it does is the $ref =
> $_GET['ref'];
> and the ref='.$ref. at the end of the for action.
>
> I appreciate this is taken out of the page so may make no sense, but if it
> is
> a standard function could somebody please tell me what it is?
>
> Many many thanks in advance
>
> that form action is set to go to a process.php page
>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

Thanks Murray

So $_GET['ref'] has no relevance to GET/POST or getting data from the form or anything, it's literally just a string of code php uses to do what you say it does

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

simbull wrote:
> So $_GET['ref'] has no relevance to GET/POST or getting data from the form or anything, it's literally just a string of code php uses to do what you say it does

No, $_GET is the PHP superglobal array that gets data from a URL query
string.

http://docs.php.net/manual/en/reserved.variables.php#reserved.variables.get

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

Well, the PHP function $_GET parses the URL for any variables, and is a
different entity entirely from the form method of "GET".

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"simbull" <webforumsuser@macromedia.com> wrote in message
news:fimnr2$j2h$1@forums.macromedia.com...
> Thanks Murray
>
> So $_GET['ref'] has no relevance to GET/POST or getting data from
> the form or anything, it's literally just a string of code php uses to do
> what you say it does

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

thanks very much you two, just ordered myself a nice php book so that should lend a hand too

Cheers

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

simbull wrote:
> just ordered myself a nice php book so that should lend a hand too

Hope it was one of mine. ;-)

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

On Thu, 29 Nov 2007 10:27:37 -0500, "Murray *ACE*"
<forums@HAHAgreat-web-sights.com> wrote:

>That's just a way of passing a variable to a page. Let's assume that the
>form page is loaded using a URL like this -
>
> http://www.example.com/yourformpage.php?ref=whatever
>
>When the form page loads, it parses the ref variable from the link, so now
>$ref has the value "whatever".

Just in case someone were to read this message out of context, it might
be more correct to say that $_GET['ref'] contains the value "whatever"
and that the code $ref=$_GET['ref'] copies that into the $ref variable.


>so that when the form is processed by details_process.php, that process page
>can act according to the value of the $ref variable, carried through from
>the page calling the form, to the form, then to the page processing the
>form.

It might also be worth noting that the form's method must be "get", not
"post" for this to all work correctly.

Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

> It might also be worth noting that the form's method must be "get", not
> "post" for this to all work correctly.

Not in the context of my reply, though. Based on the original post (which
is not completely clear), the form page LOADS with the $_GET, so I assumed
that a variable was being passed to it, which was then relayed to the
processing page. I didn't think of the alternate interpretation that you
mention.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Gary White" <reply@newsgroup.please> wrote in message
news:m7qtk3dbo771mr5t2u56qj1985jfsqnqru@4ax.com...
> On Thu, 29 Nov 2007 10:27:37 -0500, "Murray *ACE*"
> <forums@HAHAgreat-web-sights.com> wrote:
>
>>That's just a way of passing a variable to a page. Let's assume that the
>>form page is loaded using a URL like this -
>>
>> http://www.example.com/yourformpage.php?ref=whatever
>>
>>When the form page loads, it parses the ref variable from the link, so now
>>$ref has the value "whatever".
>
> Just in case someone were to read this message out of context, it might
> be more correct to say that $_GET['ref'] contains the value "whatever"
> and that the code $ref=$_GET['ref'] copies that into the $ref variable.
>
>
>>so that when the form is processed by details_process.php, that process
>>page
>>can act according to the value of the $ref variable, carried through from
>>the page calling the form, to the form, then to the page processing the
>>form.
>
> It might also be worth noting that the form's method must be "get", not
> "post" for this to all work correctly.
>
> Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

On Thu, 29 Nov 2007 11:59:12 -0500, "Murray *ACE*"
<forums@HAHAgreat-web-sights.com> wrote:

>> It might also be worth noting that the form's method must be "get", not
>> "post" for this to all work correctly.
>
>Not in the context of my reply, though. Based on the original post (which
>is not completely clear), the form page LOADS with the $_GET, so I assumed
>that a variable was being passed to it, which was then relayed to the
>processing page. I didn't think of the alternate interpretation that you
>mention.

Well, here's what you wrote:

>The form's action would create a URL like this -
>
> http://www.example.com/details_process.php?ref=whatever

If the form's action attribute includes the parameter, the form's method
should be GET if you want to pass that. It would actually be more
correct to write the value to a hidden field instead of appending the
parameter to the form's action uri, then it wouldn't matter which method
was used:

<form action=" http://www.example.com/details_process.php"
method="whatever">
<input type="hidden" name="ref" value="<?php echo $_GET['ref'];?>

Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

> If the form's action attribute includes the parameter, the form's method
> should be GET if you want to pass that.

No kidding? Hmmm - I do it that way often and it seems to work fine.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Gary White" <reply@newsgroup.please> wrote in message
news:r3fuk3diiphbourimcpa66mqif7nk0sd8u@4ax.com...
> On Thu, 29 Nov 2007 11:59:12 -0500, "Murray *ACE*"
> <forums@HAHAgreat-web-sights.com> wrote:
>
>>> It might also be worth noting that the form's method must be "get", not
>>> "post" for this to all work correctly.
>>
>>Not in the context of my reply, though. Based on the original post (which
>>is not completely clear), the form page LOADS with the $_GET, so I assumed
>>that a variable was being passed to it, which was then relayed to the
>>processing page. I didn't think of the alternate interpretation that you
>>mention.
>
> Well, here's what you wrote:
>
>>The form's action would create a URL like this -
>>
>> http://www.example.com/details_process.php?ref=whatever
>
> If the form's action attribute includes the parameter, the form's method
> should be GET if you want to pass that. It would actually be more
> correct to write the value to a hidden field instead of appending the
> parameter to the form's action uri, then it wouldn't matter which method
> was used:
>
> <form action=" http://www.example.com/details_process.php"
> method="whatever">
> <input type="hidden" name="ref" value="<?php echo $_GET['ref'];?>
>
> Gary

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 29, 2007 Nov 29, 2007

Copy link to clipboard

Copied

.oO(Gary White)

>> http://www.example.com/details_process.php?ref=whatever
>
>If the form's action attribute includes the parameter, the form's method
>should be GET if you want to pass that. It would actually be more
>correct to write the value to a hidden field instead of appending the
>parameter to the form's action uri, then it wouldn't matter which method
>was used:

><form action=" http://www.example.com/details_process.php"
>method="whatever">
><input type="hidden" name="ref" value="<?php echo $_GET['ref'];?>

I disagree. The form's action attribute is a URL, and a URL might
contain a query string. This is completely independent from the form
itself. In some cases there are reasons to use both, POST and GET.

Micha

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 30, 2007 Nov 30, 2007

Copy link to clipboard

Copied

LATEST
Well you all lost me ages ago! 🙂

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines