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
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... 
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.