Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6641489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:49:02+00:00 2026-05-25T23:49:02+00:00

I’m escaping blog posts with sqlite_escape_string(), and connecting to the database using the old

  • 0

I’m escaping blog posts with sqlite_escape_string(), and connecting to the database using the old object-oriented way.

(Yes, I know, I should use PDO, I’ll get to that later; converting this script would take quite a while.)

When I have data like: It's raining cats and dogs!, it saves this to the database: It''s raining cats and dogs!. The problem is that it comes out of the database like that, and stripslashes() doesn’t undo it. Magic Quotes is turned off.

Every time I recall that data from the database and save it again, it adds more single-quotes. How would I stop it from doing that?

Here’s the abridged submission code:

        # Grab the data from form and escape the text
        $title = sqlite_escape_string(strip_tags($_POST['title']));
        $text = sqlite_escape_string($_POST['text']);
        # Query for previous data
        $result = @$dbh->query("SELECT * FROM posts WHERE id=".$id);
        # Fetch previous data
        while($past = $result->fetchObject()) {
            $ptitle = $past->title;
            $ptext = $past->post;
        }
        # Set a base query to modify
        $base = "UPDATE posts SET ";
        # Run through scenarios
            if(stripslashes($ptitle) !== $title) { $base .= "title='".sqlite_escape_string($title)."', "; }
            if(stripslashes($ptext) !== $text) { $base .= "text='".sqlite_escape_string($text)."', "; }
            }
        # Remove last comma & space
        $base = substr($base, 0, -2);
        $base .= " WHERE id=".(int)$id;
        # Execute modified query
        @$dbh->query($base);

And here’s the code that reads the data back:

# Sanitize and set variables
$start = (int)$start;
$limit = (int)$limit;
$start = ($start - 1) * $limit;
$dbh = $this->dbh;
$this->limit = $limit;

# Query the database for post data
$this->result = $dbh->query("SELECT * FROM posts ORDER BY id desc LIMIT ".$start.", ".$limit);

public function loop() {
    # Do we have any posts?
    if(!empty($this->result)) {
        # Convert query results into something usable
        $this->cur_result = $this->result->fetchObject();
        # This while loop will remain true until we run out of posts
        while($post = $this->cur_result) {
            return true;
        }
        # At which point it turns false, ending the loop in the template file
        return false;
    }
    # We don't have any posts :(
    else {
        return false;
    }
}

public function content($excerpt = '') {
    # We didn't screw up and keep an empty query, did we?
    if(!empty($this->cur_result)) {
        echo stripslashes($this->cur_result->post);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:49:02+00:00Added an answer on May 25, 2026 at 11:49 pm

    It looks like you are escaping the data twice.

    At the beginning of your code you have:

    $title = sqlite_escape_string(strip_tags($_POST['title']));
    $text = sqlite_escape_string($_POST['text']);
    

    And then in the insert you have:

    if(stripslashes($ptitle) !== $title) { $base .= "title='".sqlite_escape_string($title)."', "; }
    if(stripslashes($ptext) !== $text) { $base .= "text='".sqlite_escape_string($text)."', "; }
    

    Remove the sqlite_escape_string from the if statements and I think the result will come out correctly now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.