Hey.
There doesn't seem to be anything wrong with that. I tried it over here and it inserted the text as expected. After issuing the two lines you pasted I had this in my database:
Some text goes here that isn't being transferred correctly. I ♥ PHP
What do you get if you print the query before you execute it? Like:
- $sql = "UPDATE Table SET caption='$caption' WHERE UserID = '$userID'";
-
echo "<pre>$sql</pre>";
-
mysql_query($sql);
One other thing, while I'm at it xD
Unless you have a good reason not to, it's generally best to insert the data into the database in a neutral format; meaning that you should not encode special chars as HTML chars
before inserting them into the database. You should only use functions like
htmlentities when the data is on the way out, just before you print it into a HTML page.
- <?php
-
// On the way in...
-
$caption = mysql_real_escape_string($_POST['p']);
-
mysql_query("UPDATE `table` SET `caption` = '{$caption}' WHERE stuff='other stuff'");
-
-
// On the way out...
-
$result = mysql_query("SELECT `caption` FROM `table`");
-
while($row = mysql_fetch_assoc($result)) {
-
echo htmlentities($row['caption'], ENT_QUOTES, 'UTF-8');
-
}
-
?>
This allows the data to be used for multiple purposes, without having to be decoded by those applications who don't simply plan on printing it as HTML. Like:
- <?php
-
// Count the number of chars total used for captions...
-
$result = mysql_query("SELECT `caption` FROM `table`");
-
$total = 0;
-
while($row = mysql_fetch_assoc($result)) {
-
$total += strlen($row['caption']);
-
}
-
?>
If you encode the text before inserting the data, the
$total there would be larger than the text displayed.