Forum Moderators: coopster

Message Too Old, No Replies

Line breaks in a text area box

         

adammc

5:56 am on Sep 30, 2004 (gmt 0)

10+ Year Member



Hi,
I am building a script for a recipe site and I need my form to automatically add a <br> when a line is skipped. Im not sure how to do it :(

add.php


<?
# this is processed when the form is submitted
# back on to this page (POST METHOD)
if ($REQUEST_METHOD=="POST") {

# setup SQL statement
$SQL = " INSERT INTO Recipes ";
$SQL = $SQL . " (name, publisher, category, summary, ingredients, method) VALUES ";
$SQL = $SQL . " ('$name', '$publisher','$category','$summary','$ingredients','$method') ";

#execute SQL statement
$result = mysql_db_query($db,"$SQL",$cid);

# check for error
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }

echo ("<P><B>Your Entry Has Been Added</B></P>\n");

}

?>

<FORM NAME="fa" ACTION="add.php" METHOD="POST">
<TABLE>
<TR><TD><B>Recipe Name: </B> </TD><TD><INPUT TYPE="text" NAME="name" SIZE=40></TD></TR>
<TR><TD><B>Publisher:</B> </TD><TD><INPUT TYPE="text" NAME="publisher" SIZE=40></TD></TR>
<TR><TD><B>Category:</B> </TD><TD><SELECT name="category" class="textbox">
<OPTION value="BBQ">BBQ</OPTION>
<OPTION value="Desserts">Desserts</OPTION>
<OPTION value="Salads">Salads</OPTION>
</SELECT></TD></TR>

<TR><TD VALIGN=TOP><B>Summary: </B> </TD><TD> <TEXTAREA NAME="summary" ROWS=3 COLS=40></TEXTAREA></TD></TR>
<TR><TD VALIGN=TOP><B>Ingredients: </B> </TD><TD> <TEXTAREA NAME="ingredients" ROWS=5 COLS=40></TEXTAREA></TD></TR>
<TR><TD VALIGN=TOP><B>Method: </B> </TD><TD> <TEXTAREA NAME="method" ROWS=5 COLS=40></TEXTAREA></TD></TR>

<TR><TH COLSPAN=2><P><INPUT TYPE="submit" VALUE="Add"></P></TH></TR>
</TABLE>
</FORM>

view.php


<?php

echo "Recipe Name: ".$myrow["name"];
echo "<br>Publisher: ".$myrow["publisher"];
echo "<br>Category: ".$myrow["category"];
echo "<br>Summary: ".$myrow["summary"];
echo "<br><br>Ingredients: ".$myrow["ingredients"];
echo "<br><br>Method: ".$myrow["method"];

?>

Any help would be GREATLY appreciated ;)

yowza

6:07 am on Sep 30, 2004 (gmt 0)

10+ Year Member



I think you're looking for -- nl2br

[us2.php.net...]

adammc

6:44 am on Sep 30, 2004 (gmt 0)

10+ Year Member



So How would i implimit the echo nl2br into my view code above?

The way i am echoing my code is a little dirrent than shown on the site you mentioned.

dreamcatcher

8:21 am on Sep 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Directly after this:

if ($REQUEST_METHOD=="POST") {

add this:

$method = nl2br($method);

:)

kumarsena

9:48 am on Sep 30, 2004 (gmt 0)

10+ Year Member



wow, i didnt that one existed,

any other functions thta exisis that deal with html formatting..? could come in handy.

kumar

coopster

1:21 pm on Sep 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Some helpful links (and you'll find even more links on these pages!):

PHP and HTML [php.net]
htmlentities() [php.net]
htmlspecialchars() [php.net]
HTTP Functions [php.net]
Features [php.net]

adammc

10:37 pm on Sep 30, 2004 (gmt 0)

10+ Year Member



Whoo Hoo! It works :)

Thank you so much guys!