Using $_POST

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
kammy
Forum Newbie
Posts: 6
Joined: Sun Feb 02, 2003 5:39 am

newbie - nl2br

Post by kammy »

I'm stuck on the The PHP Beginners Tutorial

How do I make this for post PHP 4.2

The tut shows this;

$MyTextarea = nl2br($MyTextarea);
echo($MyTextarea);

I've tried variations of this;

$MyTextarea = nl2br ($_POST['MyTextarea']);
echo $_POST['MyTextarea'];

So far I can't make it work...

Tnx.i.a.
kammy...
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Are you sure that you named a form field "MyTextarea" (and entered some text before running the form processor script - duh :lol: )?

Also, would the form send the form field name as lower case (I don't know)? If it does, $_POST['mytextarea'] ought to work.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To check what is in the $_POST array you can do:

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
at the top of the script that handles the form processing.

One thing I did notice was you have this:

Code: Select all

$MyTextarea = nl2br($_POST['MyTextarea']);
and then this:

Code: Select all

echo $_POST['MyTextarea'];
which means that you are echoing out the original variable that has not had the nl2br() function run on it. To view the text with the HTML line breaks added in you would need to do:

Code: Select all

$MyTextarea = nl2br($_POST['MyTextarea']); 
echo $MyTextarea;
or if you're not going to use $MyTextarea anywhere else, why even bother making a temporary variable - just do:

Code: Select all

echo nl2br($_POST['MyTextarea']);

Mac
kammy
Forum Newbie
Posts: 6
Joined: Sun Feb 02, 2003 5:39 am

Thanks

Post by kammy »

Great explanation.

Of course both of your options work.

It's all a bit overwhelming when you've never done any coding before.

That PHP Beginners Tutorial is by far the best I've come across so far.

kammy...

:arrow: Beginners Tutorial;
http://www.phpcomplete.com/tutorials.ph ... adTutorial
:arrow: Read in conjunction with - Working with Form Variables in PHP 4.2+;
http://www.phpcomplete.com/tutorials.ph ... adTutorial
Post Reply