TextArea form processing problem

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
Erfangc
Forum Newbie
Posts: 11
Joined: Sat Jul 29, 2006 2:21 pm

TextArea form processing problem

Post by Erfangc »

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]


Hello, I am new to the php developer's network as well as the php language itself. Please forgive me if this is the wrong forum to ask this
sort of question.

On one of my web page, a php script is supposed to retrieve a string from the global array $_POST then store the information into MySQL. On another page, I provided means for the user to view this information by accessing the database. However, whenever the data is displayed there seems to be no carrige return or new lines at all. All the characters are lined up in their cell in a marathon (the text only goes to the next line when it reaches the border of the cell, which has a fixed width). Here is the partial script I used to perform this task:

submission.php

[syntax="html"]<P>
   	<textarea name="content" rows="20" cols="60">
process_submission.php[/syntax]

Code: Select all

<?php
	//Attempt To Connect To Database
	$content = $_POST['content'];
	$title = $_POST['text_title'];
	$author = $_POST['author'];
	$host = "localhost"; //Subject To Change On The Production Server
	$user = "avantsci";
	$password = "delta08";
	$connection = mysql_connect($host,$user,$password) or die(mysql_error());
	mysql_select_db("avantsci?user?submission");
	$query = "INSERT INTO submissions (title, author, content) VALUES ('".$title ."', '".$author."', '".$content."')";
	$results = mysql_query($query) or die (mysql_error());
	include 'pre_content.php';	
?>

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]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

In HTML a linebreak is represented by the element <br />.
The data of a <textarea> element is treated like pre-formatted text (the <pre> element), a linebreak shows up as \r and/or \n (i.e. chr(13) or chr(10))
So you need the \r \n to become <br /> when you output the text as html again.

see http://de2.php.net/nl2br
Erfangc
Forum Newbie
Posts: 11
Joined: Sat Jul 29, 2006 2:21 pm

Post by Erfangc »

thanks for the prompt reply.
p.s I will no doubt follow the convention for posting code in the future.

The new line problem is solved, what about tabs?
Last edited by Erfangc on Sat Jul 29, 2006 4:35 pm, edited 1 time in total.
Erfangc
Forum Newbie
Posts: 11
Joined: Sat Jul 29, 2006 2:21 pm

Post by Erfangc »

The new line problem is solved, what about tabs?
Erfangc
Forum Newbie
Posts: 11
Joined: Sat Jul 29, 2006 2:21 pm

Post by Erfangc »

I have tried str_replace("\t"......) but it kind of didnt work. I know \t as an escape character from Java but I m not sure if the same applys in php
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

It's the same special character.

Code: Select all

$out = str_replace("\t", '&nbsp;&nbsp;', $in);
echo $out;
Post Reply