Re: preg_replce ' for use with mysql
| From: | CPT John W. Holmes | Date: | Tue, 20 Jan 2004 16:49:48 +0000 |
| Subject: | Re: preg_replce ' for use with mysql | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-175157@lists.php.net to get a copy of this message | ||
From: "Nirnimesh" <nirnimesh@students.iiit.net>
> How do I replace all ' with \' in php so that I'm able to use the mysql
> queries. Note that simply using: preg_replace("/'/", "\'", -1) is
> not what
> I'm looking for, for this does not help me. Let's say I take the address
> from a form and want to enter it into the database as it is. Now, if the
> user enters "'" the above preg_replace will work but if the user himself
> enters "\'" , during replacing, the '\' introduced is nulled by the
> effect
> of the preceeding back-slash, and the mysql query becomes somthing like:
> mysq_insert ("insert into students (id, address) values (3, '\\'')");
>
> How do I get around this problem? Is there any function which helps
> to insert everything into the mysql database as it is (does
auto-escaping).
Have you looked at the functions in the MySQL chapter?
http://us2.php.net/manual/en/function.mysql-real-escape-string.php
or just addslashes().
---John Holmes...