Joe Smith Joe Smith - 5 months ago 8x
SQL Question

Is my Update function correct (PHP)

I get an error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'WHERE name_enterprise='111'' at line 1' in C:\wamp\www\project\models\Db.class.php on line 29.

I would like to know if my query is correct, thanks in advance.

   public function update_enterprise2($name_enterprise,$address_enterprise){
$query = 'UPDATE enterprises SET name_enterprise='. $this->_db->quote($name_enterprise) .',address_enterprise'. $this->_db->quote($address_enterprise).'WHERE name_enterprise=' . $this->_db->quote($name_enterprise);


This is how you set up a prepared statement.

function update_enterprise2($name_enterprise, $address_enterprise) {
    $query = '
            UPDATE enterprises SET 
                name_enterprise = :name_enterprise,
                address_enterprise = :address_enterprise
                name_enterprise = :name_enterprise2
    if ($con = $this->_db->prepare($query)) {
            ':name_enterprise' => $name_enterprise,
            ':address_enterprise' => $address_enterprise,
            ':name_enterprise2' => $name_enterprise,

note that you can only use names parameters once, so you need to change the name in order to use them twice.