ShadowMage Posted June 28, 2012 Share Posted June 28, 2012 (edited) I'm having a bit of a situation here. I have a query which can contain apostrophes (') so obviously I'll need to escape those. The problem is, they're not escaping, but they're also not causing errors. The query runs just fine but chops off the string where the first apostrophe appears. For example:This is the string I want to enter:This is a 'test'What I actually get in the field is:This is a No error. Just chops it off at the apostrophe... Here is how I'm constructing the data for that field: $tmpDescString = '';if (isset($_POST['Description'])) { for ($x=0; $x<$types; $x++) { if ($x > 0) { $tmpDescString.=';'; } if (isset($_POST['Description'][$x])) { $tmpDescString.=mysql_real_escape_string($_POST['Description'][$x]); } }}$tmpDescString = "'".$tmpDescString."'"; As you can see, the field is actually a semicolon delimited string of several descriptions. Each description suffers the same issue. Each one is chopped off at the first apostrophe and then appended to the string. So if I have three strings:This is a 'test'Another 'test'Yet another 'test'What I actually end up with in the database is this:This is a ;Another ;Yet another ;;;;; I've tried using str_replace to replace apostrophes but that didn't work. I also tried moving the mysql_real_escape_string to the very end and escaping the entire $tmpDescString variable. IE: $tmpDescString = "'".mysql_real_escape_string($tmpDescString)."'"; That didn't work either.It isn't a character length issue either because it doesn't matter where the apostrophe is, it always chops it off at the apostrophe. WTH is going on here? I know that real_escape works because I've used it successfully in other places... EDIT: Scratch that. I don't know what I was looking at in the database, but it seems the issue was actually not using htmlentities to display the values on the page. I could swear the database showed incorrect data, but I could've been half asleep at the time... Edited June 28, 2012 by ShadowMage Link to comment Share on other sites More sharing options...
justsomeguy Posted June 28, 2012 Share Posted June 28, 2012 What does the final query look like? Link to comment Share on other sites More sharing options...
ShadowMage Posted June 28, 2012 Author Share Posted June 28, 2012 See my edit above. If I could, I would delete this topic for fear of embarrassment. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now