i have a string variable which has these characters-> ' in between them, so wen i try to insert the values into the my database it gives me an error. Any thing that can be done about it?
yea, that was useful, but now the issue i m facing is, those variables also have / in the starting and end, i cannot use str_replace and replace them as i need / in the middle of the string also the string has special characters
Where's the problem? Forward slashes remain untouched. Don't use stripslashes() as they suggest. Just apply mysql_real_escape_string() once on the variable you want to insert and it should work. Alternatively, you can try addslashes().
if you have magic quotes On, you have to use stripslashes before mysql_real_escape_string, otherwise you will have \\' instead of \'
You dont need to place ` at all, but with a $var which you will be placing as a value you will need '$var', you will get a error if you state $query = "INSERT INTO `table` (name, age) VALUES ('$name', '$age')"; // should be $query = "INSERT INTO table (name, age) VALUES ('$name', '$age')"; PHP: