Solved

need to close or escape the single quote in mysql

Posted on 2013-01-11
2
180 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 82

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now