?
Solved

need to close or escape the single quote in mysql

Posted on 2013-01-11
2
Medium Priority
?
189 Views
Last Modified: 2013-01-11
     foreach($_POST['id'] as $id =>$v){
     //echo '<br>post foreach update';   
        $q = 'update '.$tablename.' set ';
        foreach ($cols as &$columnname) {
          $q.=$columnname.'=\''.$_POST[$columnname][$id].'\',';
          }        
        $q = substr($q,'',-1);
        $q.=' where id='.$_POST['id'][$id].'';
        echo '<br>'.$q;
        mysql_query ($q); 
 }

Open in new window



if the post contains
'

example
sally's
friend's
james'
she said, 'this'

the query will not work
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 38769314
"mysql_real_escape_string" or the newer versions are used to 'escape' quotes and other problem characters before they are inserted into a MySQL database.
http://php.net/manual/en/function.mysql-real-escape-string.php
0
 

Author Closing Comment

by:rgb192
ID: 38769475
this escaped '
thanks
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
The viewer will learn how to count occurrences of each item in an array.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question