problem with apostrophes in text to be entered in db

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
chevy
Forum Newbie
Posts: 3
Joined: Fri Aug 19, 2005 3:51 pm

problem with apostrophes in text to be entered in db

Post by chevy »

I need to send data in a textarea to a memo field in the db(access 2000). the problem is apostrophes or quotes or single quotes can easily end up in the text. I have tried the following but the apostrophe keeps causing an error. I cannot find a solution for this.

$squo = "'";
$dquo = """;
$notes = stripslashes(ereg_replace("'",$squo,$_POST["other_notes"]));
$notes = stripslashes(ereg_replace('"',$dquo,$_POST["other_notes"]));
$str_lines = "Insert into lead_lines(empID, leadID, date_, notes) VALUES(".$_POST["pick_emp"].",".odbc_result($rs_leadid, "callID").",'".$_POST["date_entered"]."','".$notes."')";

the resulting sql statement is:

Insert into lead_lines(empID, leadID, date_, notes) VALUES(1,14,'8/19/2005',' This guy seems like a real easy going dude. Might've been high when he ordered.')

The problem is in the might've, i've also tried to insert it like might\'ve -- doesn't work

Is there a way to make it literally write ' instead of placing a ' ?

Because I ran the query in access with the character code rather than the apostrophe and it worked.

Any help is appreciated
korto
Forum Commoner
Posts: 36
Joined: Thu Aug 18, 2005 6:30 am
Location: Greece
Contact:

Post by korto »

There is a certain syntax that breaks the ' and displays it correctly nut as far as I know there is also a "magic quotes" option in php configuration that might apply to your case. Have a look at php.net for it, hope it helps
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Post Reply