Handle double quotes " with value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Handle double quotes " with value

Post by shafiq2626 »

Hello!
How to handle " with value to insert in mysql query.

like

Code: Select all

$nId = $this->InsertTable('actor',"Name, Rate,Path","\"".$this->name."\",\"" .$this->rate."\",\"" .$this->path."\"");
single quotes and semicolon handle by this code but if insert double quotes like " with value like abc" then give error

pls Please help ASAP.

thanks
Last edited by Benjamin on Tue May 12, 2009 11:37 am, edited 1 time in total.
Reason: Changed code type from text to php.
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Re: Solved To Handle double quotes " with value

Post by shafiq2626 »

Hello!

I wrote a function

Code: Select all

function quote( $text )
    {
        if ( get_magic_quotes_gpc() )
            $text = stripslashes($text);
 
        return '\'' . mysql_real_escape_string($text) . '\'';
    }
and pass every value to this function

like

Code: Select all

$connet->quote($_POST['name']);

you can do it and be relax
Last edited by Benjamin on Tue May 12, 2009 11:37 am, edited 1 time in total.
Reason: Changed code type from text to php.
Defiline
Forum Commoner
Posts: 59
Joined: Tue May 05, 2009 5:34 pm

Re: Handle double quotes " with value

Post by Defiline »

Does it work? :)
No, It doest not.

Code: Select all

 
function quote($text) {
    if (get_magic_quotes_gpc()) {
        $text = stripslashes($text);
    }
    
    return mysql_real_escape_string($text);
}
But it is not correct still.
Post Reply