Re: getcsv error
| From: | Brian Hazelton | Date: | Mon, 26 Oct 2009 00:58:15 +0000 |
| Subject: | Re: getcsv error | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-299330@lists.php.net to get a copy of this message | ||
Brian Hazelton wrote:
I have a script which uploads csv data into a database. This works well and has worked in every instance so far. However what I am noticing is that today, even if I escape the data before putting it into mysql it will not enter a line if it has a single quote, once I take out the single quote it enters it into the database so I know it is the single quote, is this an error or are single quotes not allowed in csv...? I figured out part of the problem. The problem lies with one of my functions for cleaning the data before putting it into the database. I have a function, see below, that will clean the data to put into mysql and work whether magic quotes is on or off. It is not working because I echo the query and the part I need escaped is not being escaped. I try mysql_real_escape_string and it is being escaped by that so I think the problem is something with my function, if anyone can help that would be appreciated.function clean($str){ if(get_magic_quotes_gpc()){
stripslashes($str);
mysql_real_escape_string($str);
return $str;
}
else{
mysql_real_escape_string($str);
return $str;
}
}
$name = 'O'Leksy';
$cleaned_name = clean($name);
echo of $cleaned name = O'Leksy';
if mysql_real_escape_string is used it echoes O\'Leksy';