Jump to content

DOuble Quote and Escape Problem


seran128

Recommended Posts

I have a form that posts html code to a mysql db blob field, from a WYSIWYG editor.

HOw can I get this to save if there are escape characters in the html code being posted and is there a special way of getting the code back out?

the code that posts

[code]$table = "webcontent_regions";
$content=$_POST["test1"];
$id=$_POST["id"];
$sql="update $table set content='$content' where regionId='$id'";
//echo $sql;
$result=mysql_query($sql,$connection) or die(mysql_error());
header("location: ../list/wc_list.php");[/code]

The code that retrieves the data

[code]function getpagecontent($inId){
global $connection;
$sql="select content from webcontent_regions where regionId='$inId'";
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
$content=$row['content'];
}
echo $content;
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/25732-double-quote-and-escape-problem/
Share on other sites

First off know that you don't always need double quotes and that sometimes single slashes are more effective such as $_POST['test1'];

Here is how you do it...  so in the first code block... you add in
$content = add_slashes($_POST['test1']);

and in your function before the echo you'd add
$content = strip_slashes($content);

-- should work for you... 
I did that and now it is posting to the db but now I have another problem.

When I past html code into the WYSIWYG editor it saves fine but when i call the function that displays the code

<? getpagecontent(1); ?>

It shows the html code on the page and not the product of the code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.