Can't pass variable from forms : PHP Version 4.2

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cathari
Forum Newbie
Posts: 11
Joined: Mon May 13, 2002 9:51 pm

Can't pass variable from forms : PHP Version 4.2

Post 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>

-------------------------------------------------------------------------------------
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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:
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

cathari:

Code: Select all

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

Code: Select all

if(isset($_POST&#1111;'submit'])){
cathari
Forum Newbie
Posts: 11
Joined: Mon May 13, 2002 9:51 pm

Post 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.
Post Reply