rynox
10-14-2004, 03:41 PM
I'm trying to take a user-inputted string and insert into a database. So when I'm building the query in PHP, I want to replace a single quote ' with two-single quotes '' (not a double quote) so that SQL can parse the query correctly. Sounds simple, but I keep getting strange results. Here is the code in question:
...str_replace("''","'",$_POST['Title'])...
For example, when the $_POST['Title'] variable = Ptty 359 Won't Boot
The resulting string is:
Ptty 359 Won\''t Boot
Why is PHP so kind as to add the slash in there? It's causing my SQL query to bomb. Help, I'm pulling my hair out.
...str_replace("''","'",$_POST['Title'])...
For example, when the $_POST['Title'] variable = Ptty 359 Won't Boot
The resulting string is:
Ptty 359 Won\''t Boot
Why is PHP so kind as to add the slash in there? It's causing my SQL query to bomb. Help, I'm pulling my hair out.