Escape Data In/Out of db
| From: | tedd | Date: | Thu, 09 Apr 2009 14:35:40 +0000 |
| Subject: | Escape Data In/Out of db | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-291292@lists.php.net to get a copy of this message | ||
Hi gang:
I'm gathering information from a user, storing that data in a db, and then showing it back to the user. It's a simple process and can bee seen here in this address book demo (not real people):
http://php1.net/a/edit-db-demo
I gather information from the user via a $_POST[]; like this:
$last_name = trim($_POST['last_name']);
Then I pass it through mysql_real_escape_string() like so --
$last_name = mysql_real_escape_string($last_name);
-- and then I put that data into my table via an UPDATE.
Then when I pull data from the table, I do this --
$last_name = htmlentities($row['last_name']);
-- and show that data to the user. That's what I'm supposed to do right?
So, why is it that when I enter the name "O'Brian", the entry comes back "O/'Brian"?
So what's wrong and how do I fix it?
Cheers,
tedd
PS: I know that I'm supposed to know this, but that part of my brain is on vacation -- I can't afford for all of me to go on vacation at one time.
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com