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

The Archive Base Latest Questions

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

My server is running PHP 5.2.17 and I have disabled magic quotes with a

  • 0

My server is running PHP 5.2.17 and I have disabled magic quotes with a php.ini file. I have an array of strings some are like

abcd “efg” hij’k lmnop’q

I am escaping them for insertion into a mysql database using the following code

foreach($array as &$data) {
    mysql_real_escape_string($data);
}

I am then constructing my sql like so

$sql='INSERT INTO table VALUES('.
     '"'.$array[0].'", '.
     '"'.$array[1].'", '.
     '"'.$array[2].'")';

I get an error when I try to execute my query. I output the $sql variable when I get an error and it seems that mysql_real_escape_string is only escaping either single quotes or double quotes.

If my $sql variable is created using single quotes with the column values in double quotes like it is above then single quotes are escaped but double quotes are not.

If I switch the quotes so that the $sql variable is created using double quotes and the column values are in single quotes only the double quotes are escaped.

Can anyone figure out what might be going wrong?

**UPDATE

Matchu figured it out. I have changed my code to the following and it works:

foreach($row as &$data) {
    $data = mysql_real_escape_string($data);
}
  • 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-25T11:49:40+00:00Added an answer on May 25, 2026 at 11:49 am

    mysql_real_escape_string does not modify the string object itself, even if you use & to pass by reference instead of by value. Instead, it returns an escaped copy of the string. You can’t just run the function; you have to assign its output to a variable.

    I’m not in a place where I can test right now, but Joe says this does the trick:

    $data = mysql_real_escape_string($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On one Linux Server running Apache and PHP 5, we have multiple Virtual Hosts
I have a php server that is running my domain name. For testing purposes
I have a PHP script (running on a Linux server) that ouputs the names
I have a PHP server at home for development. It is running: Ubuntu 9.10
I'm running on a shared *NIX server (run by Site5). I have a php
I'm running on win2003 server, PHP 526, via the cmd-line. I have a cmdline
I have php 5.1.6 running on my CentOS 5 server running Apache 2.2.3 I
Windows 2008 R2 server running PHP 5.3. I have URL Rewrite for IIS working
I have two PHP arrays like so: Array of X records containing the ID
I have a script which uploads data to my web server running Apache/PHP 5.3,

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.