LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2002, 11:44 AM   #1
niehls
Member
 
Registered: Jun 2002
Location: Sweden
Distribution: slack, redhat
Posts: 91

Rep: Reputation: 15
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?
 
Old 06-15-2002, 09:37 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
I think you need to assign a value to name.

Code:
<input type="text" name="name" value="crabboy">
 
Old 06-16-2002, 04:02 AM   #3
niehls
Member
 
Registered: Jun 2002
Location: Sweden
Distribution: slack, redhat
Posts: 91

Original Poster
Rep: Reputation: 15
it gets a value when something is typed in the textbox.
 
Old 06-16-2002, 08:35 AM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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
 
Old 06-16-2002, 09:27 AM   #5
niehls
Member
 
Registered: Jun 2002
Location: Sweden
Distribution: slack, redhat
Posts: 91

Original Poster
Rep: Reputation: 15
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.
 
Old 06-16-2002, 10:10 AM   #6
dorward
Member
 
Registered: Sep 2001
Distribution: Gentoo
Posts: 760

Rep: Reputation: 31
Try accessing it as:
Code:
$_POST['input_name']
 
Old 06-16-2002, 06:49 PM   #7
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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.
 
Old 06-17-2002, 06:52 AM   #8
niehls
Member
 
Registered: Jun 2002
Location: Sweden
Distribution: slack, redhat
Posts: 91

Original Poster
Rep: Reputation: 15
yeah.
echo "hello $_POST[name]"; works
thx
 
Old 06-17-2002, 01:30 PM   #9
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Turn on the register_globals directive on the php.ini file and you will able to access the variable as $name.
 
Old 10-14-2003, 01:24 PM   #10
powerfast
LQ Newbie
 
Registered: Oct 2003
Posts: 1

Rep: Reputation: 0
Question 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?
 
Old 10-14-2003, 05:19 PM   #11
niehls
Member
 
Registered: Jun 2002
Location: Sweden
Distribution: slack, redhat
Posts: 91

Original Poster
Rep: Reputation: 15
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing groupadd to execv() returned error msg: "file already locked." walwali Programming 9 11-22-2010 06:36 AM
form action ="?" ... where is my form posting to? verbatim Programming 2 05-23-2005 06:55 PM
what does "try passing init=\ option to kernel" mean? Danforth Linux - General 3 05-11-2004 06:57 PM
Boot messages not the same as "dmesg" or "/var/log/messages"? massai Linux - General 5 03-10-2004 12:18 AM
problms w/ php 4.2.1 mozilla 0.9.9 enctype="mutlipart/form-data" w/ phpWebSite 0.8.3 coea77 Linux - Software 1 10-10-2002 03:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration