PDA

View Full Version : Multiline Database


neuro
03-14-2007, 08:48 AM
Hi..

I have a multiline text area (called "Description") in my form. Once the user click submit button, everything will be submitted into the database. Now in my SQL database field called "Description" will store text which submitted from the multiline text area.

The problem now in database the data shows in singleline, so when i tried to shows the data in my webpage, that Description data like a one long sentence. Is there anyway i can put it in multiline?

thanks in advance.

kona72
03-14-2007, 01:41 PM
post your code....

lux
03-14-2007, 03:14 PM
either implement something like fckeditor (google it) which is very easy to include in your page

or

visit php.net and search for this function in the function list: nl2br()

neuro
03-14-2007, 04:02 PM
Thanks for the reply..

I did few changes on my website, right now i'm using CSS style to design my layout. To solve one fo the problem i used the following code:

===================================
#RightContent2 {
width:467px;
background:#FFFFFF;
position: absolute;
top: 595px;
left: 269px;}
===================================

As the result:

This is what i type in (this data will go into my database)
http://i2.photobucket.com/albums/y2/excolted/Case1.jpg

This is how it display on my main page
http://i2.photobucket.com/albums/y2/excolted/Result1.jpg

So far so good right... but then i tried something else (what if someone trying to do something that i'm going to do) and found a new problem.

This is wat i type in (this data will go to my database)
http://i2.photobucket.com/albums/y2/excolted/Case2.jpg

This is how it display on my main page
http://i2.photobucket.com/albums/y2/excolted/Result2.jpg

Notice that the field "description" change the layout of the webpage (the one with text "aaaaaa....")

@ lux8uk

so do u think that function still can work to solve this?

lux
03-14-2007, 05:09 PM
the reason that happens is because there are no spaces between any of the characters in the string and really when will you ever see that happen except for this example.

i would over look this as not being a problem. but for arguments sake (and to further your knowledge of php) you could look up the strlen() function and use it to separate any strings over a certain length.

but in all honesty i would ignore it

(im now sitting here nervously waiting for someone to tell me i'm wrong! hehe)

lux
03-14-2007, 05:11 PM
example taken from php.net


<?php
function wordlength($txt, $limit)
{
$words = explode(' ', $txt);

foreach($words as $v)
{
if(strlen($v) > $limit)
{
return false;
}
}

return true;
}
?>

Uses like this:
<?php

$txt = "Onelongword and some small ones";

if(!wordlength($txt, 10))
{
die("One of the words where too long");
}

?>

neuro
03-14-2007, 05:14 PM
Yeah... actually the odd that someone might actually do that is very small, but i wan to be prepared, just in case someone did that.

so can u tell me more about "strlen()" or is there any link i could visit? sorry it might sound little bit too much coz i know i can just google it. hehe

Ah.. nvm.. u actually posted some example. haha... i'll get back once i try to implement those codes, but first i'll finish the whole design for the website.

Thanks again.

lux
03-14-2007, 05:16 PM
you must have been typing the last message when i posted the example, haha

give me a shout if you need anything more

regards

neuro
03-15-2007, 06:43 AM
hm...

I have this code:


if ($submit && $data2 && $data3 && $data4 && $data5 && $data6 && $data7 && $data8){
///////////////////////////////////////////
$query = sprintf("INSERT into EmployerList (Username, Password, CompanyName, CompanyAddress, CompanyPhone, CompanyEmail, ContactPerson) values ('$data2', '$data3', '$data4', '$data5', '$data6', '$data7', '$data8')");
mysql_query($query)or die(mysql_error());
echo '<script type="text/javascript"> window.alert("Thank You!"); </script>';
header ("location: Index.php");
exit;
///////////////////////////////////////////
}elseif($submit) {
echo '<script type="text/javascript"> window.alert("One of your fields is empty !"); </script>';
}


The part where the condition is true. i manage to display the "Thank You!" message, but then once i clicked "OK" button, i got this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/boontau/public_html/ads/RegisterForm.php:20) in /home/boontau/public_html/ads/RegisterForm.php on line 21

lux
03-15-2007, 08:46 AM
make sure your php code is above any html and that there are no whitespaces

in other words move all your php to the top of the php document

regards

neuro
03-15-2007, 09:19 AM
i dun get it...

is there anyway i can modified the javascript, so when i press ok button it reload index.php? coz right now everytime i press ok button from the pop up it reload the same page.