RE: [PHP] Passing form values to PHP

2004-03-30 Thread Jay Blanchard
[snip]
Anyone have any ideas as to what's up. I hope its just something silly
that
I'm missing being a newby to PHP and all.
[/snip]

There is a feature in the php.ini called register_globals. If you look
in your php.ini you will see that it is off by default and some of the
books may have missed this as the default previously was on. You would
be best to learn PHP with it off as most of the community does it that
way for various reasons.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing form values to PHP

2004-03-30 Thread Burhan Khalid
Ciemny, Jessica wrote:
Hey every, I'm new to the group and to PHP (3 days now) and I would like to
ask a question. I purchased a book on PHP a day or so ago and as I'm going
through the book it comes to a point where it talks about passing html form
values to PHP. So I type up the examples from the book, both the html file
and the PHP file and I run it and I don't get anything when the PHP file is
accessed. H puzzling! I don't get any errors at all, but the values just
aren't coming across.
The book says that I should be able to take the name=xyz value from the
HTML form and just use it as a regular variable ($xyz) in the PHP file. But
this doesn't work. 

After much digging on web pages and through email lists I found reference to
something called the $_POST variable. This seems to be the only way that I
can make the PHP file use the name=xyz values from the HTML file. So in
the PHP file I would have to use the variable $_POST[xyz] to get the form
value returned. 

Anyone have any ideas as to what's up. I hope its just something silly that
I'm missing being a newby to PHP and all.
The problem here is that the book is written for a PHP setup where 
register_globals is assumed to be turned on. This can be a security 
risk, so as of PHP 4.2.x, register_globals has been turned off by 
default (before it was on by default).

Register globals is a directive that tells PHP to automatically create 
variables from requested information (be it POST or GET). More 
information about why register_globals is a bad idea can be found at the 
following PHP manual page [ http://www.php.net/register_globals ]

I will include small versions of the file here for reference:
[ snipped ]

So I guess my question ultimately is, what are the different ways in which
form data can be passed to a PHP script?
Data is transferred using forms in two methods. GET or POST. The 
difference between the two (the main difference) is that the data from a 
GET request is appended to the URL. Such a request would be :

http://www.google.com/search?q=php+tutorials

and data from a POST request is actually sent as part of the HTTP 
request (in the header), so its not viewable in the browser URL.

PHP provides (since PHP version 4.2) two arrays, $_POST and $_GET for 
each of the above methods. There is also a third array, $_REQUEST which 
holds all information sent in the request.

These arrays are called superglobals because they are available 
throughout your pages without any effort from your part. Each array 
consists of a key and a value. The key is whatever is the name attribute 
of your form value.

An example :

form method=POST action=process.php
input type=text name=firstname size=10 /
input type=submit name=submit value=submit /
/form
process.php :

?php

  //Turn up error reporting
  //to the max level
  error_reporting(E_ALL);
  //Print out the contents
  //of the $_POST array
  //so we can see what it
  //contains.
  echo pre; print_r($_POST); echo /pre;
?
When you run the above script with the associated form, you will see the 
format of the $_POST array. It will contain an element with the key 
firstname and the value will be whatever the user entered in that text 
box. It will also contain an element with the key submit whose value 
is submit (that's our submit button).

Hopefully this helps, and welcome to PHP :)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Passing form values to PHP

2004-03-30 Thread Vishal Patel
Try this:

extract($_POST);

extract --  Import variables into the current symbol table from an array

All of my forms have worked without $_POST or $_GET. Is there a reason for
inavailability of variables???

Its a good practice to use $_POST for security reasons.

Vishal.

-Original Message-
From: Ciemny, Jessica [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 30, 2004 10:30 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Passing form values to PHP


Hey every, I'm new to the group and to PHP (3 days now) and I would like to
ask a question. I purchased a book on PHP a day or so ago and as I'm going
through the book it comes to a point where it talks about passing html form
values to PHP. So I type up the examples from the book, both the html file
and the PHP file and I run it and I don't get anything when the PHP file is
accessed. H puzzling! I don't get any errors at all, but the values just
aren't coming across.

The book says that I should be able to take the name=xyz value from the
HTML form and just use it as a regular variable ($xyz) in the PHP file. But
this doesn't work.

After much digging on web pages and through email lists I found reference to
something called the $_POST variable. This seems to be the only way that I
can make the PHP file use the name=xyz values from the HTML file. So in
the PHP file I would have to use the variable $_POST[xyz] to get the form
value returned.

Anyone have any ideas as to what's up. I hope its just something silly that
I'm missing being a newby to PHP and all.

I will include small versions of the file here for reference:

HTML FILE
-

htmlbody
form action=x.php method=post
Please enter your name:
input type=text name=xyz
input type=submit value=submit
/form
/body/html


PHP FILE (Doesn't Work)
-
htmlbody
?php
echo(The value of name is $xyz);
?
/body/html


PHP FILE (Does Work)
-
htmlbody
?php
echo(The value of name is $_POST[xyz]);
?
/body/html

So I guess my question ultimately is, what are the different ways in which
form data can be passed to a PHP script?

Thanks you,

Jessica

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing Form Values

2002-06-26 Thread Erik Price


On Tuesday, June 25, 2002, at 06:56  PM, Phillip S. Baker wrote:

 When the form is submitted I want to values passed to a pop-up window.
 I am aware of the need for Javascript for the pop-up window, but how do 
 I get the values from the form passed to the new window so I can use 
 them in further scripts.
 I can write the javascript to do the popup window and use the onSubmit 
 command, but I cannot figure out how to pass the values with a regular 
 submit button.
 Thanks

Pass them along the querystring, so that when the JavaScript popup 
window opens and it goes to a certain page, those values are part of 
that URL.  As GET variables.

// Your PHP vars:
$var1 = 'Metroid';
$var2 = 'Metal Gear';

// Create a querystring:
$PHPqueryString = var1= . $var1 . var2= . $var2;

// echo the browser string for the popup:
print a href=\\ onclick=\openPopup(
. $PHPqueryString
. \Popup!/a\n;

// here's your JavaScript function
function openPopup(queryString)
{
var detailwindow = window.open('./target.php?' + queryString,
'windowname',
'toolbar=no,directories=no,
status=no,menubar=no,resizable=yes,
copyhistory=no,scrollbars=yes,
width=500,height=300');
detailwindow.moveTo('150', '150');
}

Now in your new script you can access these GET vars from PHP or from JS!


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php