Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert text box for html and back

Status
Not open for further replies.

davejam

Technical User
Jan 6, 2004
313
GB
previously posted in javascript forum advised to post in php

Good afternoon (gmt),

I am using a text box to enter detail that will be used to print text to a php web page.

I need to

1.remove or replace any code that may cause problems with my php code such as apostrophies and quotes (maybe with ascii equivalents)

2.format the entered text so it can be used within a web format such as replacing line breaks with <br> or <p> and & with &amp;.....

3.format back to original so can be edited within a text box... although i could just save the html format to a seperate firld and keep the original for editing...

not sure

any ideas or suggestions would be a great help and much appreciated

thankyou in advance


daveJam

*two wrongs don't make a right..... but three lefts do!!!!*
 
not sure what the issue is here? some pointers though:

1. make sure that magic_quotes_runtime and magic_quotes_gpc are turned off always.
2. if you are going to store the data in a database run it through mysql_real_escape_string before inserting it. Remember to enquote the data as well.
Code:
$data = $_POST['textbox'];
$query = 'Insert into tablename (id, textbox) values (NULL, '".mysql_real_escape_string($data)."'";
3. assuming an id of 1, to edit the data do this

Code:
$query = 'select textbox from tablename where id=1';
$data = mysql_result(myqsl_query($query), 0, 0);
echo <<<HTML
<textarea name="textbox">$data</textarea>
HTML;

4. to display the data
Code:
$query = 'select textbox from tablename where id=1';
$data = mysql_result(myqsl_query($query), 0, 0);
echo nl2br($data);

it's that simple!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top