472,953 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,953 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 17593
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.