Forum Moderators: coopster

Message Too Old, No Replies

Problems with $_POST

Can you help a php newbie :-)

         

trillianjedi

9:29 am on Apr 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm doing more and more of this these days, but suspect I haven't quite got my head around it because I'm trying to do something really basic and it isn't working...

In a php page called "widgets.php" I have the following:-

<?
echo "<input name=\"WODGET\" type=\"text\" class=post id=\"wodget\" style=\"WIDTH: 300px\" value=\"".$_POST['wodget']."\">";
?>

The idea is to fill this form object with a wodget variable passed to the script, like this:-

http://www.example.com/widgets.php?wodget=TrillianJedi

It doesn't seem to work. It doesn't create an error, the form text object is displayed, it's just the value is blank rather than "TrillianJedi".

Do I need to initialise something before using $_POST to obtain the passed variables?

Many thanks,

TJ

trillianjedi

9:51 am on Apr 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Aha! Sorry, just found the $_GET array variable and got it working now....

Living and learning!

TJ

coopster

11:47 am on Apr 21, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'll often dump the $GLOBALS variable to the browser to troubleshoot too, TJ. Comes in pretty handy sometimes.

print '<pre>'; print_r($GLOBALS); exit('</pre>');

Slide that little snippet in where you want to stop processing your script to have a look at things. If you are within a function, you may want to add the get_defined_vars() [php.net] to that list as well -- and you can get much fancier than that, of course, but this is a good start.

trillianjedi

12:38 pm on Apr 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Coop - just before I try that, can you let me know what it does?

Does it print out all current vars, or just ones handed to the script via a form or URL?

TJ

dreamcatcher

2:15 pm on Apr 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



print_r is indeed a useful little code snippet.

You can view more info about this function on the PHP website:

http://uk2.php.net/manual/en/function.print-r.php [uk2.php.net]

trillianjedi

2:23 pm on Apr 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very handy - thanks guys.

TJ