We help IT Professionals succeed at work.

php wont update if content has a '

Cheryl Lander
on
199 Views
Last Modified: 2013-12-13
Ive got a form which uses fckeditor.

It works fine but when I add text (content) to the form it wont update if the content has
and apostrophe in it.

Naturally Im going to need to add apostrophes in the contents website so how do I get around this.
Comment
Watch Question

you cannot use the ' in your code when dealing with the fckeditor

Author

Commented:
So what options do i have?
use \"

remember this is in your code ppl can use ' in the fckeditor

Author

Commented:
dont really follow.

Author

Commented:
I find it hard ot believe that you couldt write the following in fckeditor.

today I can't find a html editor.

If so are there any alternatives?

Author

Commented:
Ive just gone onto the fckeditor site and done a test on their demo. It works fine.

                         <p>' &quot;</p>
<br />

So I can only assume its a php code error when inserting it into the database.
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
Hi,

It is simple issue,

you need to replace ' ..

after receiving the text from fckeditor, you have to use replace function to replace the ' to `

 
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:

$fcktext = $_POST['fckeditor'];
 
$formatt_text = str_replace($fcktext, "'","`");

Open in new window

Author

Commented:
logudotcom:
not sure where to make this change.

I have my form page, then I have my processing page (insert)
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
you have to make in the processing page...

where you are receiving and insert?
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
if u can, post some code on the processing page, i will modify it?
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
one more suggestion,

even you can apply this function -->mysql_escape_string()

 instead of str_replace(),


<?php
$item = "Zak's Laptop";
$escaped_item = mysql_escape_string($item);
printf("Escaped string: %s\n", $escaped_item);
?>

Open in new window

Author

Commented:
Form page.

    <tr>
      <td valign="top"><div align="right" class="textstandard">
        <div align="left">Information<span class="textRecord"></span></div>
      </div>      </td>
     
      <td valign="top" class="textstandard"><img src="images/icon_circlearrow.gif" width="11" height="11" /></td>
      <td><textarea id="MyTextarea" name="ud_content"><? echo $row["content"]; ?></textarea></td>
    </tr>

------------------------------------------------------------------------

Processing page.
$query="UPDATE pages SET content='$ud_content' WHERE pageid='$ud_pageid'";

Author

Commented:
note I have other form fields but this is the fckeditor form.
LAMP Developer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I went into it and added a ' to the content and processed the code and came back to view an nothing had changed.

Author

Commented:
All ok recoded the page and it works great.

Thanks so much.
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
actually, mysql_escape_string() will help you to safer insert/update... it won't replace '
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
do u need any help again?

Author

Commented:
ok so if you think its better.

Do you want me to open up another question?


actually, mysql_escape_string() will help you to safer insert/update... it won't replace '
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
may be, you can open new question

Author

Commented:
done.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.