Go Back   CP Web Hosting - reseller hosting > Server Scripting > PHP
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2007, 09:47 AM
Senior Member
 
Join Date: Apr 2007
Posts: 347
Default want to escape ' and "

I want to escape ' and ". I can't figure out how to do this.
I guess the easiest way is to just add a \ to them, but how to do that?
BTW this is to stop some innocent SQL injection on my site.
Reply With Quote
  #2 (permalink)  
Old 06-28-2007, 09:50 AM
Senior Member
 
Join Date: May 2007
Posts: 284
Default

Quote:
Originally Posted by stargate View Post
I want to escape ' and ". I can't figure out how to do this.
I guess the easiest way is to just add a \ to them, but how to do that?
BTW this is to stop some innocent SQL injection on my site.
You can use the function addslashes() to escape all of the " and ' characters.
Reply With Quote
  #3 (permalink)  
Old 06-28-2007, 09:51 AM
Senior Member
 
Join Date: Mar 2007
Posts: 193
Default

The proper way to prevent SQL injection is to use parameterised queries.
Reply With Quote
  #4 (permalink)  
Old 06-28-2007, 09:54 AM
Senior Member
 
Join Date: May 2007
Posts: 217
Default

also try this

Code:
<?php
$value = stripslashes($value);
// to strip the slash.
$value = mysql_real_escape_string($value);
// to add slash.
?>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:27 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0