Page 1 of 1

PHP + Textarea + MySQL

Posted: Fri Jan 05, 2007 3:08 am
by amiira
Hi all php:ers!

I'm currently stuck with an annoying problem:

* I want to present text that has been put in through a textarea->into a data base->and then fetched with mySQL->and presented with a phpcommand...

I've got it all working but i want to be able to present the text as it was put in, eg:

bla bla bla bla

bla bla
- bla bla bla


becomes:
bla bla bla bla bla bla
bla bla -bla bla

i want it to be formatted the same way as it was put in, is that possible? if so, how on earth do i do that :D

actually, it's much like this post i just made... :D
cheers, Amiira

Posted: Fri Jan 05, 2007 3:15 am
by Kieran Huggins

Code: Select all

<pre> is the output text in these tags? </pre>

<textarea> or one of these? </textarea>

Posted: Fri Jan 05, 2007 3:20 am
by Flamie
you want to use nl2br() before echo'ing the text you grabbed from the database, or save it after nl2br()'ing it.
solution A:
->save textarea to database
->grab text from database
->apply nl2br() on it
->echo text

solution B:
->nl2br() text from textarea
->save text to database
->grab text from database
->echo text

Posted: Fri Jan 05, 2007 3:22 am
by amiira
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hmm? i use a form in which i have textarea as input, when i print the text, stored in the database i use

Code: Select all

<?php echo "$text" ?>
i have a separate php script that takes the textarea text from with the help of the textarea name="news" tag...

that script looks like this:

Code: Select all

<?php
//phpinfo();
//header("Content-type:text/html;charset=utf-8");
$connection = "connection.php";
include($connection);



mysql_select_db ('info');
$NODE=$HTTP_POST_VARS['forlag'];
//utf8_encode($NODE);
$query = "UPDATE info SET Info ='$NODE' WHERE User ='forlag'";
$result = mysql_query($query);

if ($result) header('Location: admin.php');
else echo "not inserted";

?>
... would the formatting still work with this, or do i need to do it another way?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Jan 05, 2007 3:25 am
by Flamie
hmm? i use a form in which i have textarea as input, when i print the text, stored in the database i use
<?php echo "$text" ?>
if $text is the textarea text saved in the database, try:

Code: Select all

<?php
echo nl2br($text);
?>

Posted: Fri Jan 05, 2007 3:26 am
by amiira
and, oh, sorry i dont echo the text i: print utf8_encode

... :oops:

is it still possible?

Posted: Fri Jan 05, 2007 3:29 am
by amiira
Ahh, i think it works now, with the nl2br, thans alot!!! all of u!!!