LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   form "post" not passing var (https://www.linuxquestions.org/questions/programming-9/form-post-not-passing-var-23481/)

niehls 06-15-2002 11:44 AM

form "post" not passing var
 
programming php in windows.
now have a very basic problem. a simple script will illustrate my problem:

contents of exampe.php:

<form action="example2.php" method="post">
Name:
<input type="text" name="name"><br>
<input type="submit" value="accept">
</form>

contents of example2.php:

<?
echo "hello $name";
?>

now, my problem is that example2.php doesn't output $name. it seems like the value of "name" is not stored in $name.

anyone knows how to configure/fix this problem?

crabboy 06-15-2002 09:37 PM

I think you need to assign a value to name.

Code:

<input type="text" name="name" value="crabboy">

niehls 06-16-2002 04:02 AM

it gets a value when something is typed in the textbox.

crabboy 06-16-2002 08:35 AM

I pasted your example into a file and it works on my machine.
Code:

// example.php

<?php

Header("Content-type: text/html");

print "<html>\n";
print "<form action=\"example2.php\" method=\"post\">\n";
print "Name:";
print "<input type=\"text\" name=\"name\"><br>\n";
print "<input type=\"submit\" value=\"accept\">\n";
print "</form>";
print "</html>\n";
?>

Code:

// example2.php

<?
echo "hello: $name";
?>

Results from typing "crabboy" in text box
Code:

hello: crabboy

niehls 06-16-2002 09:27 AM

of course it works!
i know it works..that's not the issue. the problem is that some configuration or something makes it NOT work on MY computer.
my question was if anyone knew what could be the cause of this error.

dorward 06-16-2002 10:10 AM

Try accessing it as:
Code:

$_POST['input_name']

crabboy 06-16-2002 06:49 PM

Try putting a phpinfo() call after the print in example2.php. Look under the PHP Variables section to see if a _POST["name"] exists. You should also see a ton of other PHP Variables.

niehls 06-17-2002 06:52 AM

yeah.
echo "hello $_POST[name]"; works
thx

crabboy 06-17-2002 01:30 PM

Turn on the register_globals directive on the php.ini file and you will able to access the variable as $name.

powerfast 10-14-2003 01:24 PM

Re: form "post" not passing var
 
Hi niehls

I have the same problem in my server redhat ver 9

You resolve the problem, how?

Thanks,

OPC
+-----------------------------------------------------------------
Quote:

Originally posted by niehls
programming php in windows.
now have a very basic problem. a simple script will illustrate my problem:

contents of exampe.php:

<form action="example2.php" method="post">
Name:
<input type="text" name="name"><br>
<input type="submit" value="accept">
</form>

contents of example2.php:

<?
echo "hello $name";
?>

now, my problem is that example2.php doesn't output $name. it seems like the value of "name" is not stored in $name.

anyone knows how to configure/fix this problem?


niehls 10-14-2003 05:19 PM

well, read the posts above and the problem is most probably solved. if register_globals is turned off in your php configuration file you have to either turn it on (not recommended) or use the proper globals assigned to these variables.
access the variable by $_POST["name"] (in my case).
turning register globals off is not recommended both because it might cause problems with multiple variables ending up with the same name and it is also a security vulnerability. (people might put &foo=bar in the adress field which will assign your variables other values.
hope this helps. otherwise post again. quoting your script would probably help if the problem remains.
Cheers


All times are GMT -5. The time now is 01:30 AM.