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
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