-3

I have a table (cod, nom) but the nom field has (') and (") and blank spaces. I want to clean all that table using this code:

<?php
class ConexionDB extends PDO {
  public function __construct () {
  try {
      parent:: __construct('mysql:host=localhost;dbname=xprueba;charset=utf8', 'root','key');
      parent:: setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      } catch (Exception $ex) { die ('Database is not exist');  }  }
  function __destruct(){
  }
}
$BD = new ConexionDB();

$replace_these = ['"','\''];
$replace_with = ['',''];

$sql = "UPDATE xxx SET nom = :nom";

$sth = $BD->prepare($sql);
$nom = trim(str_replace($replace_these, $replace_with, :nom));

$sth->bindParam(':nom', $nom);
$sth->execute();

I get this message: Parse error: syntax error, unexpected ':' in C\:limpia4.php on line 19 Is when I use trim() Can somebody help me?

1 Answers1

1

I assume that line 19 is:

$nom = trim(str_replace($replace_these, $replace_with, :nom));

because you misspelled variable $nom by writing :nom. Change it to:

$nom = trim(str_replace($replace_these, $replace_with, $nom));

and it should work. BTW What is that variable for? It is not assigned anywhere in the code you provided.

Tomasz Kowalczyk
  • 10,472
  • 6
  • 52
  • 68
  • I have a table with data (cod, nom) and the nom field needs to cleanning for example: nom1 = 'ANGEL VEGA, nom2= "JUAN" after to run my code the table be nom1=ANGEL VEGA, nom2=JUAN. – Piropeator Jun 08 '16 at 22:29