Escaping Quotes

  • jordonshaw
  • Student
  • Student
  • User avatar
  • Joined: Dec 30, 2008
  • Posts: 91
  • Loc: Tennessee
  • Status: Offline

Post February 9th, 2009, 11:53 pm

Ok guys, here for some help again :D With MySql if you have a form, you can escape the quotes by using the command mysql_real_escape_string. The problem is, I have MS SQL and not My Sql. This command does not work on MSSql and I can't figure out how to escape the quotes, so that I can post quotes in the database. Can somebody help?

Thanks,
Jordon
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post February 9th, 2009, 11:53 pm

  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post February 10th, 2009, 2:53 pm

Have your tried mssql_real_escape_string()?

If that doesn't work try addslashes();
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Joined: Dec 30, 2008
  • Posts: 91
  • Loc: Tennessee
  • Status: Offline

Post February 10th, 2009, 3:39 pm

Actually mssql_real_escape_string() did not work. That's what I tried at first. I spent several hours working this last night; however, in the end, I found something that would work:

Code: [ Select ]
$cr_name = stripslashes(str_replace("'", "''", ($_POST['cr_name'])));


Basically stripslashes wouldn't work on it own. After research the only thing MSSQL has a issue with is ' and if you double it, by using '' then it will comment it out. So, that's why I used a string replace from ' to ''; however, when I did this, it posted in the Database like jordon\'s and I could not get rid of the slash, unless I used stripslashes, so as you see, that's how I came up with this line of code, which seems to be working great!
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post February 10th, 2009, 5:45 pm

alright, cool. Glad you got it figured out.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 184 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.