Re: working with ' in SQL
| From: | Richard Davey | Date: | Thu, 04 Mar 2004 15:38:57 +0000 |
| Subject: | Re: working with ' in SQL | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-33306@lists.php.net to get a copy of this message | ||
Hello Adam,
Thursday, March 4, 2004, 3:30:32 PM, you wrote:
AW> Hi, I have an SQL statement that is ran when data is submitted through a
AW> form. When someone types in a word with an ' such as farmer's the SQL
AW> statement fails. I tried $_POST[data] =
AW> addslashes($_POST[data]); before
AW> executing the SQL statement, but the statement still fails. any
AW> suggestions? using words without a ' works fine.
$_POST['data'] = addslashes($_POST['data']);
will work - you need the quotes or the array element won't be found.
Here is a function that will addslashes to an entire array (in this
instance $_POST) if you want:
<?
function addslash (&$item1, $key)
{
$item1 = addslashes($item1);
}
array_walk($_POST, 'addslash');
?>
--
Best regards,
Richard Davey
http://www.phpcommunity.org/wiki/296.html