473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Trying to store and retrieve formatted text from MYSQL using PHP - Newbee seeking advice

I am trying to store formatted text (windows format) into a MySQL
database and then retrieve it. The field in the database is a
varchar. I cut and paste the test into a form field formatted, then
call the PHP program to add the record using POST. When I get the
text out, it has lost it's formatting. Formatting in the text is
achieved by multiple spaces not tabs, but even multiple spaces are
converted to a single space and the carrage return/line feeds are
lost. Below is the basic code I am calling when I click POST in the
form.

I would really appreciate advice on how I can make this work. I have
looked through many sites, and have not seen anything with deals with
this sort of problem.

Thanks in advance.

James.

-----------------
Code Below.
-----------------

<?PHP
$date=$_POST['date'];
$title=$_POST['title'];
$scores=$_POST['scores'];

$db=mysql_connect("localhost","root") or die ("cannot connect");
mysql_select_db("mydb") or die ("can not select database");
$query="INSERT INTO scores (scoresdate, scorestitle, scorestext)
VALUES ('$date', '$title', '$scores')";
printf($query);
$result=mysql_query($query) or die ("Invalid Query : " .
mysql_error());
echo "Thank you!";
?>
Jul 17 '05 #1
6 17660
When I get the
text out, it has lost it's formatting. Formatting in the text is
achieved by multiple spaces not tabs, but even multiple spaces are
converted to a single space and the carrage return/line feeds are
lost.


HTML ignores multiple spaces and only displays 1
Jul 17 '05 #2
I noticed that Message-ID:
<7d**************************@posting.google.com > from James Turner
contained the following:
I would really appreciate advice on how I can make this work. I have
looked through many sites, and have not seen anything with deals with
this sort of problem.


The formatting is probably still there, it just does not work in html.
You need to change all occurrences of a space with &nbsp; and all
newlines with <br>.

So assuming your output is in $string

print nl2br(str_replace(" ","&nbsp;",stripslashes($string)));

But the html won't be pretty...

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3

"James Turner" <ja**********@westnet.com.au> wrote in message
news:7d**************************@posting.google.c om...
I am trying to store formatted text (windows format) into a MySQL
database and then retrieve it.

<snip>

Does serialize() not cut the mustard?

Garp
Jul 17 '05 #4
> I am trying to store formatted text (windows format) into a MySQL
database and then retrieve it. The field in the database is a
varchar. I cut and paste the test into a form field formatted, then
call the PHP program to add the record using POST. When I get the
text out, it has lost it's formatting. Formatting in the text is
achieved by multiple spaces not tabs, but even multiple spaces are
converted to a single space and the carrage return/line feeds are
lost. Below is the basic code I am calling when I click POST in the
form.

You can use the <pre> tag for that (preformatted text):
<pre>Your text here</pre>
Your formatting (spaces/line feeds) will be retained, but most browsers
will render the text in a fixed-pitch font, so that may be a disadvantage.

Regards,
Henk Burgstra
Jul 17 '05 #5
Henk Burgstra <eg****@xs4all.nl> wrote in
news:pa****************************@xs4all.nl:
I am trying to store formatted text (windows format) into a MySQL
database and then retrieve it. The field in the database is a
varchar. I cut and paste the test into a form field formatted, then
call the PHP program to add the record using POST. When I get the
text out, it has lost it's formatting. Formatting in the text is
achieved by multiple spaces not tabs, but even multiple spaces are
converted to a single space and the carrage return/line feeds are
lost. Below is the basic code I am calling when I click POST in the
form.

You can use the <pre> tag for that (preformatted text):
<pre>Your text here</pre>
Your formatting (spaces/line feeds) will be retained, but most
browsers will render the text in a fixed-pitch font, so that may be a
disadvantage.


If it's "formatted with multiple spaces" then it almost certainly *needs*
to be displayed in a fixed-pitch font to retain its alignment.

Remember that "<" and "&" still have to be "entified" even in <pre> text;
it would be a good idea to run it through htmlspecialchars().
Jul 17 '05 #6
Thanks everyone for your assistance. The simple HTML tag did the
trick. Why I did not think of that myself, I don't know.

Thanks again,

James.

Eric Bohlman <eb******@earthlink.net> wrote in message news:<Xn*******************************@130.133.1. 4>...
Henk Burgstra <eg****@xs4all.nl> wrote in
news:pa****************************@xs4all.nl:
I am trying to store formatted text (windows format) into a MySQL
database and then retrieve it. The field in the database is a
varchar. I cut and paste the test into a form field formatted, then
call the PHP program to add the record using POST. When I get the
text out, it has lost it's formatting. Formatting in the text is
achieved by multiple spaces not tabs, but even multiple spaces are
converted to a single space and the carrage return/line feeds are
lost. Below is the basic code I am calling when I click POST in the
form.

You can use the <pre> tag for that (preformatted text):
<pre>Your text here</pre>
Your formatting (spaces/line feeds) will be retained, but most
browsers will render the text in a fixed-pitch font, so that may be a
disadvantage.


If it's "formatted with multiple spaces" then it almost certainly *needs*
to be displayed in a fixed-pitch font to retain its alignment.

Remember that "<" and "&" still have to be "entified" even in <pre> text;
it would be a good idea to run it through htmlspecialchars().

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Klaus Kragelund | last post by:
Hi I'm using DreamWeaver 2004 on a Win2k machine to create my homepage. After spending several hours of mingling with ASP I discover that my ISP doesn't support Access databases. So I turned to...
5
by: Roy Gourgi | last post by:
Hi, I am used to working in Visual FoxPro and I would like to be able to create a database and store and retrieve information from it. What is the simplest way to do it and what should I be...
0
by: Gert | last post by:
Hi, I need to store a array() of byte to a mysql field. I created a field in mysql of type varbinary. But storing and retrieving gives problems. Please help. The strTemp = EnDeCrypt(txt,...
7
by: eholz1 | last post by:
Hello Group, Perhaps you can help me. I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
3
by: JM | last post by:
Before storing information from a form in database I perform follwing operations on it : $path = mysql_real_escape_string(strip_tags(trim(urldecode($_POST)))); $summary =...
3
by: Alfred | last post by:
I want to post text field data from these HTML TEXTAREA tags to a PostgreSQL database and have it reappear back on another page exactly as I had typed it. Over the years I have done this but only...
4
chumlyumly
by: chumlyumly | last post by:
Hi - I'm working with PHP5 MySQL Mac OSX I've developed two pages where a user can input his/her info, which goes to a MySQL database. The first page is supposed to pass the newly created...
25
by: pereges | last post by:
Hello, I'm trying to build a database driven website for a library management system. The database is stored on a remote server which all of my team mates can access. I've installed MySQL, PHP and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.