Page 1 of 1

Can't pass variable from forms : PHP Version 4.2

Posted: Mon May 13, 2002 9:51 pm
by cathari
Hi,

I'm using version 4.0.6 before and i recently upgraded my version to 4.2 and now everything isn't working. I know that they turned the register_global off and i'm reading a lot of the alternatives but when I tried it myself it doesn't seem to work. Can somebody look at this code:

How come i'm getting notice like undefined variable submit?

Thanks in advance. I really need to figure out the problem.

-------------------------------------------------------------------------------------

<?php
$PHP_SELF = $_SERVER['PHP_SELF'];

//Handle Input here
//Check if $submit has a value of "Go" - The Validator
if($submit=="Go"){
//The Processor
echo("You wrote ".$_POST["you_wrote"]);
echo("<br>You could have done whatever you want with the input instead");
exit;
}

?>

<!-- The Frontend HTML form -->
<form action="<?php echo $PHP_SELF ?>" method="POST" >
<p>Input a word <input type="text" size="20" name="you_wrote">
<input type="submit" name="submit" value="Go"></p>
</form>

-------------------------------------------------------------------------------------

Posted: Mon May 13, 2002 10:14 pm
by lc
Why not just try:

Code: Select all

if ($submit == "Go")&#123;
echo "you wrote $you_wrote";
echo "<br>You could have done whatever you want with the input instead";
&#125;
should work... or at least that's how I do it ;) Though I never use a value for submit... does that work?

Posted: Mon May 13, 2002 10:23 pm
by volka
why checking for post-data at all?
$_REQUEST['submit'] $_REQUEST['you_wrote'] should contain the values wether they were posted or passed by GET.

Since I hate to ignore all the warnings in my apache-log I check the existence of the key before trying to access it
if (array_key_exists('submit', $_REQUEST) && strcmp($_REQUEST['submit'], 'GO')==0) .....
F*** the performance :twisted:

Posted: Mon May 13, 2002 10:36 pm
by jason
cathari:

Code: Select all

if($submit=="Go")&#123;
change to

Code: Select all

if(isset($_POST&#1111;'submit'])){

Posted: Mon May 13, 2002 11:12 pm
by cathari
It worked!!!

Thanks a lot. I did some modifications on

Code: Select all

echo("You wrote ".$_Post&#1111;'you_wrote']);

To

    echo("You wrote ".$_REQUEST&#1111;'you_wrote']);
and it worked just fine.