Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with Apostraphes in php and mysql 1

Status
Not open for further replies.

Jimmy211

Technical User
Aug 8, 2002
42
US
I have what is probably a very newbie question. I’m using php to query a mysql database and having problems with apostrophes ‘.

On my table I have a manufacturer name and a product name, with a given manufacturer having multiple products. I first run a select statement to get the distinct manufacturer’s names, and within a loop I step through each manufacturer name and run a second select statement that selects all the products for that manufacturer.

The problem I have is when there is an apostrophe in the manufacturer name, the select query fails. The query looks like this:

$query2 = “SELECT PRODUCT_NAME FROM msdslist WHERE MFG_NAME =’$mfgr’ ORDER BY PRODUCT_NAME”;

Where $mfgr is the manufacturer name selected in the first query.

With a record where the name is O’brien, the query fails. I’ve tried swapping quotes and apostrophes, at which the select statement doesn’t return any records.

So my question is, how do you handle data with apostrophes or quotes in it?

Thanks in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top