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 9122493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:07:02+00:00 2026-06-17T06:07:02+00:00

I have a form for a blog post and whenever I have a single

  • 0

I have a form for a blog post and whenever I have a single quote (for example, that’s) the SQL insert code breaks. I have tried using mysql_real_escape_string:

$Description = mysql_real_escape_string($_POST['Description']);

But this doesn’t work. I tried using htmlspecialchars() too, but for these posts I need to be able to use HTML code for adding links and images.

I updated the SQL code to like a guide said to do and still I didn’t work. Then I can update it if there are no single quotes, so the code does work, but the single quotes are causing lots of trouble

        $SQL = "UPDATE Posts SET Title = '$Title',LinkTitle = '$LinkTitle',MainPicture = '$MainPic',Description ='".$Description."',Maintext = '$Main',Type = '$SubCategory',Featured = '$Featured'
    ,category = '$Category',thumbnail='$thumb'
    WHERE ID = '$id'";

Fix

Thanks to Gaucho for the solution the problem was I was using mysqli to connect to the database. changing the connection code to normal mysql_connect fixed the problem.

  • 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-06-17T06:07:03+00:00Added an answer on June 17, 2026 at 6:07 am

    Use this code, with your database name and password, and report the error you’re are obtaining.

    The mysql_real_escape_string is not the problem in your query since in my case it is working fine. Let us know even your PHP and MySQL version.

     <?php
         // Connect to your database
         mysql_connect("localhost","yourDBuserName","yourDBpassword");
    
         // Specify database
         mysql_select_db("yourDBname") or die;
    
         //Build SQL query
         $Description = mysql_real_escape_string("that's amore");
         $query = "select * from Posts where Description ='" . $Description . "'";
         $queryResult=mysql_query($query);
         if (!$queryResult) {
             $message  = 'Invalid query: ' . mysql_error() . "\n";
             $message .= 'Whole query: ' . $query;
             die($message);
         }
         die ($queryResult);
     ?>
    

    I even suggest you PhpEd to debug your code.
    Note: the result of mysql_real_escape_string in my sample is “that\\’s amore”.
    Any echoed string that doesn’t start with Invalid.. means that the query is running fine.

    Note 2: this is the right method to connect to your server.

    If you want to connect using mySqli, use the following code to connect, since you are doing it in the wrong way:

    $mysqli = @new mysqli('yourDBaddress', 'yourDBuserName', 'yourDBpassword', 'yourDBname');
    
    if ($mysqli->connect_errno) {
        die('Connect Error: ' . $mysqli->connect_errno);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been writing some code that creates a generic blog. Its features are
Scenario: I have a blog that I want to make a post to. I
I have a donations form in my WordPress blog and the Donation Description is
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
I have form in my page, I am using ajax.beginform(). Inside this form I
I've been working on a small blog form but have been having trouble with
I am writing a view that drives the submit button on a blog post
Building my Django app, I have been using some code from django-basic-app , in
I have been reading this blog post and this stack overflow post but I
I'm working on PHP/MySQL based 'Blog Post' System, the posts can have multiple Categories,

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.