Page 1 of 1

Get value from a LIST/MENUS form to a $variable

Posted: Wed Mar 31, 2004 10:32 am
by fasp
i got some problems with my php webpage but....
maybe... my problem is really not the code.


CHeck this out:

I got this pc in my job, i used to program php there, it was a client from an intranet. I used to upload all my php files to the server and run the php's from there (server). It works fine, so i i saw one of my pages on php and i have this:

Code: Select all

echo '<form name="form1" method="post" action="">'; 
echo '<input type="text" name="textfield">'; 
echo '<input type="submit" name="submit" value="submit">'; 
echo '</form>'; 
$x=$textfield; <----LOOK 
echo '<br>'; 
echo $x; <----LOOK
thats extremly normal! its a basic procedure, and it works fine.

BUT.... i started 2 used my laptop to make php files, i have the apache server on it, and at the same time im client, i have to put the php files in to this directory C:\Program Files\...... Group\Apache\htdocs and they run perfectly... BUT i have this problem.....that same code makes me an ERROR:

when i use this :
$x=$textfield;

show me this:
Notice: Undefined variable: textfield in c:\program files\apache group\apache\htdocs\4\index.php on line 271


I saw the php.ini of my lapto to compare with the pc of my office to see any differencies, and it seems like its another version, i dunno, but the version in my laptop is php4.
Anyway, i change some things that look familiar... but still dont work... somebody have any idea?!


Posted: Wed Mar 31, 2004 10:37 am
by qads
you have to use $_POST['textfield'], not $textfield in new php versions :) .

so its $x = $_POST['textfield'];

help me...

Posted: Wed Mar 31, 2004 10:58 am
by fasp
firts of all, thanks for your time, to you qads and to anyone who have been read this topic; second of all... sorry about my english, i dont use
this lenguage very often, i use spanish im from Mexico.

Well, i know that $_POST, $_REQUEST, $_Get are use to pass global variables to another page, to the next page generally, but in this case i forgot to say
that im using this $x=$textfield; in realtime, or in the same page, not in another pages. So, if a make a value change in the list/menu, it will appear that value on a textfield in less than a second (i guess :D ), the variables are not going anywhere.. or any other page, is all in the same webpage.

I tried $_POST and notice me the same error.

For exxample we have this list/menu element and a textfield,
so in the list/menu u have 1,2,3,4,5,6,7,8,9,10 for the list/menu values,
then we have a table's database with this fields "table: num.pregunta and pregunta" (num.pregunta=question number and pregunta=question)
so if u select a "1" in the list/menu element, with some php and mysql code, it will search in the table's database the number "1" and in the textfield it will put the question number "1".

Thats seems to work, what i cant understand its why i cant pass a value of a textfield or a list/menu element to a $variable in the same page?!?!?!?!?

HELP ME PLEASE[/img]

Posted: Wed Mar 31, 2004 12:15 pm
by magicrobotmonkey
You submit the form to the same page, right? I don't know maybe you should put the name of the php file in action="" (i.e. action = "page.php"

Posted: Wed Mar 31, 2004 2:51 pm
by joel1220
Hello,

i would like to share my little experience.... I'm new to PHP and i get same Notice.. variable not defined.... what i did i change the setting in php.ini register_globals = On ...

and it works fine... i know its not recommended to set it to ON, but maybe the more you make programs in PHP you can find the answers.

hope this help...

thanks...

thanks

Posted: Wed Mar 31, 2004 3:17 pm
by fasp
thanks to all for sharing and answer this post
You submit the form to the same page, right? I don't know maybe you should put the name of the php file in action="" (i.e. action = "page.php"
didnt work.. why? couse in the next page u told the pho this: $_request['textfield'] or $_get['textfield'] or $_post['textfield'], but it says to me Notice: Undefined variable: textfield

so, still my problem beenig that i cant grab the value of some form , any element (list/menus, textfield, textarea, etc).. it still saying that annoyin NOTICE :cry:

WHats the worst of all...?? i got the register_globals ON

just visualize this:

Code: Select all

echo '<form name="form1" method="post" action="">';//action is empty, so its reload this same page
echo '  <input type="text" name="textfield">';
 echo '<input type="submit" name="Submit" value="Submit">';
echo '</form>';
$x=$textfield;
echo '<br><br>';
echo $x;
its a basic procedure, but in the line where is "$x=$textfield;" send me that NOTICE. Do u see the action tag? :arrow: action="" so, if u click the sumbmit button... it just reload to the same page :D

maybe i need to post the php.ini? but is too long and maybe it would take more than 5 post (if it is a character limit).

still..... HELP ME

Posted: Wed Mar 31, 2004 3:36 pm
by mudkicker
write action=$_SERVER['PHP_SELF']

Re: thanks

Posted: Thu Apr 01, 2004 1:33 am
by twigletmac
fasp wrote:$_request['textfield'] or $_get['textfield'] or $_post['textfield']
if you use that then you will have a problem - PHP is casesensitive and $_post is not the same thing as $_POST. The correct arrays would be $_POST, $_GET and $_REQUEST - all capitals.

Mac