Help......Passing Search string containing single quotes

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

Locked
anirbanb2004
Forum Newbie
Posts: 23
Joined: Sun Oct 15, 2006 4:21 pm

Help......Passing Search string containing single quotes

Post by anirbanb2004 »

Hi I am trying to write a code that is simple..I will pass a variable $word and it will search all the rows in a MySql table.
Now If the string in $word contains single quote(') then it is creating problem.
Please help me It is very important... :(

Code: Select all

$string=$_POST['name']; 

$query="select * from Words where Word='$string'"; 
$result=mysql_query($query);
Now if $string ="Citta' " then it will create problem.....
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Code: Select all

$string = mysql_real_escape_string($_POST['name']);
Locked