Solved

need to close or escape the single quote in mysql

Posted on 2013-01-11
2
181 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
2 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now