Embedded quotes

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
cdjohn
Forum Newbie
Posts: 1
Joined: Wed Oct 08, 2008 5:04 am

Embedded quotes

Post by cdjohn »

I am using PHp to insert data into a mysql table. as follows

$query = "INSERT INTO database (category, catname, active) VALUES('$category', '$catname', '$active' ) ";

The problem is if the variable catname contains quotes (for example - LAST YEAR'S STOCK -) I get mysql errors.

Any suggestions?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Embedded quotes

Post by papa »

User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Embedded quotes

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Embedded quotes

Post by papa »

My bad.

However I had problems with ' before I added these lines:

Code: Select all

 
if(get_magic_quotes_gpc()) {
    $name = stripslashes($name);
}
And the using mysq_real_escape_string to your insert.
Post Reply