Re: Sending a string with $_POST/$_GET

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> I want to write a string to a variable and use $_POST or $_GET to retrieve
> it on another page.
> 
> I keep gettting an undefined index errror. Can someone show me how this is
> done?
/*
How are you trying to accomplish this?  Are you setting the $_GET in
the page code, or using a hidden form?  (If you are using the form,
you can skip this part.  If you aren't, or don't know what I mean,
read on!)  For example:

This code (page1.php):
<?php 
$_GET['myvalue'] = 'This is MY GET VALUE!!!!';
$_POST['myvalue'] = 'This is MY POST VALUE!!!!';
?>

With this code (page2.php):
<?php
echo $_GET['myvalue'];
echo $_POST['myvalue'];
?>
Will not return an error, but the second page won't echo anything. 
However, if you access page2.php with the URL like this:
http://localhost/page2.php?myvalue=This is MY GET VALUE!!!!

The first line will output: "This is MY GET VALUE!!!!"

To get the second line to work, you will need to use this:
(page1.php)
<form action="page2.php" method="post">
<input type="hidden" value="This is MY POST VALUE!!!!">
<input type="submit">
</form>

When the button is clicked, page2.php, which is the same as before,
will load, and the second line will cause the output of "This is MY
POST VALUE!!!!".  You can make both lines of page2.php work by
changing the action attribute of the form to "page2.php?myvalue=This
is MY GET VALUE!!!!".  That way, they will both work.
*/
> Do I have to use session_start() ?
/*
This would be better.  You can use sessions the way I think you are
trying to use $_GET and $_POST.  Just start the session on the first
page, and set an element in $_SESSION and on the next page you can
start the session again and read the value out of the array.  Like
this:

(page1.php)
<?php
session_start();
$_SESSION['test'] = 'test value';
?>

(page2.php)
<?php 
session_start();
echo $_SESSION['test'];
?>

The page, page2.php, will show "test value" if you run page1.php
first.  $_SESSION is probably the easiest of all the superglobals to
use.

Try those, and if I'm completely off-base, and not even helping, try
posting some code, which is ALWAYS a good thing to do.  A big post
asking for help never hurt anyone.  Most people almost never read the
short ones.

Happy coding!!!
*/

-- 
disguised.jedi@xxxxxxxxx

PHP rocks!
"Knowledge is Power.  Power Corrupts.  Go to school, become evil"

Disclaimer: Any disclaimer attached to this message may be ignored. 
However, I must say that the ENTIRE contents of this message are
subject to other's criticism, corrections, and speculations.

This message is Certified Virus Free

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux