Some records update, some don't

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rhecker
Forum Contributor
Posts: 178
Joined: Fri Jul 11, 2008 5:49 pm

Some records update, some don't

Post 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?
rhecker
Forum Contributor
Posts: 178
Joined: Fri Jul 11, 2008 5:49 pm

Re: Some records update, some don't

Post 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); 
  }}
Post Reply