Page 1 of 1

Some records update, some don't

Posted: Thu Mar 17, 2011 5:52 pm
by rhecker
I am working with a table that came from a previous project. I have a cms for the client to edit text areas formated using TinyMCE. If I create new records, they are fine and I can retrieve them and edit them, but some of the original records will not update to the MySQL database, and I can't figure out the pattern. I originally ran the posted data through mysql_real_escape_string, then added htmlentities to see if that would help get MySQL to accept the data.

Code: Select all

foreach ($_POST as $k=>$v){
$v = htmlentities($v, ENT_QUOTES, "UTF-8");
$v = mysql_real_escape_string($v);
}
Any ideas?

Re: Some records update, some don't

Posted: Fri Mar 18, 2011 1:34 am
by rhecker
I think I have this sorted out now. mysql_real_escape_string wasn't really running in the code as posted. The following code seems to do the trick:

Code: Select all

  foreach ($_POST as $key => $value) { 
  if (!is_array($value)){
    $_POST[$key] = mysql_real_escape_string($value); 
  }}