Simon336697
asked on
Displaying output when editing gives be <br /> tags
Hi everyone.
Guys, on inserting records into a mysql database, im using the following..
$bothDescription = mysql_real_escape_string(n l2br($_POS T['bothdes criptionar ea']));
So, let's say, i insert the following...
Hi
this is line 2
this is line 3
On display in a browser, I get the following which is good.
Hi
this is line 2
this is line 3
But, on editing a record, Im getting the following.....
Hi<br />
this is line 2<br />
this is line 3
Im not sure what im doing wrong here.
On INSERTING RECORDS, im using
mysql_real_escape_string
AND
nl2br (because I want to preserve the way i have typed in including any carriage returns)
It is just the edit part im having the <br> tags showing, which I dont want to show when i am editng a record.
I know you guys have advised me to use mysql_real_escape_string when inserting records, which I am doing.
But using mysql_real_escape_string alone does not preserve any carriage returns or line breaks you insert, which is why i am also using nl2br with mysql_real_escape_string.
Any help greatly appreciated.
Guys, on inserting records into a mysql database, im using the following..
$bothDescription = mysql_real_escape_string(n
So, let's say, i insert the following...
Hi
this is line 2
this is line 3
On display in a browser, I get the following which is good.
Hi
this is line 2
this is line 3
But, on editing a record, Im getting the following.....
Hi<br />
this is line 2<br />
this is line 3
Im not sure what im doing wrong here.
On INSERTING RECORDS, im using
mysql_real_escape_string
AND
nl2br (because I want to preserve the way i have typed in including any carriage returns)
It is just the edit part im having the <br> tags showing, which I dont want to show when i am editng a record.
I know you guys have advised me to use mysql_real_escape_string when inserting records, which I am doing.
But using mysql_real_escape_string alone does not preserve any carriage returns or line breaks you insert, which is why i am also using nl2br with mysql_real_escape_string.
Any help greatly appreciated.
Sorry, didn't read this:
" know you guys have advised me to use mysql_real_escape_string when inserting records, which I am doing.
But using mysql_real_escape_string alone does not preserve any carriage returns or line breaks you insert, which is why i am also using nl2br with mysql_real_escape_string.
"
But I do it like I said myself and that normally works perfect, not using mysql_real_escape_string btw.
" know you guys have advised me to use mysql_real_escape_string when inserting records, which I am doing.
But using mysql_real_escape_string alone does not preserve any carriage returns or line breaks you insert, which is why i am also using nl2br with mysql_real_escape_string.
"
But I do it like I said myself and that normally works perfect, not using mysql_real_escape_string btw.
ASKER
Hi fourice, mate thank you for your kind help.
I will test once again bud just to make sure and post back results.
I will test once again bud just to make sure and post back results.
Ok, but keep in mind that you may never store a variable in the db right away (without some proper checks). Reading my post perhaps gives you that idea.
The idea is that you can store carriage returns without nl2br. For ouput to the browser you can use that function and for filling your textarea (with the newlines) you can just use the stored data.
The idea is that you can store carriage returns without nl2br. For ouput to the browser you can use that function and for filling your textarea (with the newlines) you can just use the stored data.
ASKER
fourice,
If id just use mysql_real_escape_string for insert,
This is line 1
This is line 2
This is line 3
This is line 4
with
$bothDescription = mysql_real_escape_string($ _POST['bot hdescripti onarea']);
On viewing the record in the database, it is seen as follows..
Please see the file attached.
How would I display this in a browser with new lines preserved?
as-seen-from-mysql.jpg
If id just use mysql_real_escape_string for insert,
This is line 1
This is line 2
This is line 3
This is line 4
with
$bothDescription = mysql_real_escape_string($
On viewing the record in the database, it is seen as follows..
Please see the file attached.
How would I display this in a browser with new lines preserved?
as-seen-from-mysql.jpg
You should be able to do something like:
$strQuery = "SELECT * FROM entries_ent WHERE name_ent='Go figure'";
$result = mysql_query($strQuery);
$row = mysql_fetch_array($result) ;
echo nl2br($row['description_en t']);
Typed it out of my head, so I hope it's ok.
$strQuery = "SELECT * FROM entries_ent WHERE name_ent='Go figure'";
$result = mysql_query($strQuery);
$row = mysql_fetch_array($result)
echo nl2br($row['description_en
Typed it out of my head, so I hope it's ok.
ASKER
Mate thanks for your help on this.
I tried that but that does not work, and I think it is because there has to be \n tags already in the database, which in the printscreen I posted, there is none.
There are only paragraph tags eg. ||
I tried that but that does not work, and I think it is because there has to be \n tags already in the database, which in the printscreen I posted, there is none.
There are only paragraph tags eg. ||
ASKER
If i insert a record like below...
Line 1<br>
Line 2
With your method, it does work....eg. output is:
Line 1
Line 2
But I dont want to have to type <br> tags when inserting records, especially in a textarea where I might want to cut and paste whole blocks of text with new lines, paragraphs, brs already there, and want to preserve all this formatting on output.
Line 1<br>
Line 2
With your method, it does work....eg. output is:
Line 1
Line 2
But I dont want to have to type <br> tags when inserting records, especially in a textarea where I might want to cut and paste whole blocks of text with new lines, paragraphs, brs already there, and want to preserve all this formatting on output.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
fourice youre the best, thank you mate.......sorry for the delay getting back to you :>)
Ill play with this thanks fourice :>)
Ill play with this thanks fourice :>)
ASKER
Thanks again fourice ... take care mate :>)
So:
$bothDescription = mysql_real_escape_string($
and for output use:
echo nl2br($variableName);