简体   繁体   中英

Unknown column '2' in 'where clause'

its a simple code but I'm just learning it so... I can't seem to find what my error is exactly:

"UPDATE `".$table_name_4_updating."`
            SET id_capuchon = `".$id_selector_4_updating."`,
                referencia_capuchon= `".$referencia_4_updating."`,
                medida_capuchon= `".$medida_4_updating."`,
                material_capuchon= `".$material_4_updating."`,
                calibre_capuchon= `".$calibre_4_updating."`,
                impresion_capuchon= `".$impresion_4_updating."`,
                presentacion_capuchon= `".$presentacion_4_updating."`
             WHERE id_capuchon=`".$id_selector_4_updating."`";

I tried changing the the WHERE clause to WHERE id_capuchon= '.$id_selector_4_updating.' and other different ways but all it does is changes from unknown column foobar in field list

You should change the backtick ( ` ) characters to single quotes ( ' ).

Example:

UPDATE
    $table_name_4_updating
    SET
        id_capuchon = '$id_selector_4_updating',
        referencia_capuchon = '$referencia_4_updating',
        medida_capuchon = '$medida_4_updating',
        material_capuchon = '$material_4_updating',
        calibre_capuchon = '$calibre_4_updating',
        impresion_capuchon = '$impresion_4_updating',
        presentacion_capuchon = '$presentacion_4_updating'
    WHERE id_capuchon = '$id_selector_4_updating'

You're using `backticks` around the value in the WHERE clause (and in every assignment too, actually).
This type of quotes is used in SQL to refer to a field name . So here, MySQL is looking for the field named "2" (the value of your variable $id_selector_4_updating ) but this field doesn't exist, hence the error.
You should remove them:

 $sql = "UPDATE $table_name_4_updating SET
             id_capuchon = '$id_selector_4_updating',
             referencia_capuchon = '$referencia_4_updating',
             medida_capuchon = '$medida_4_updating',
             material_capuchon = '$material_4_updating',
             calibre_capuchon = '$calibre_4_updating',
             impresion_capuchon = '$impresion_4_updating',
             presentacion_capuchon = '$presentacion_4_updating'
         WHERE id_capuchon ='$id_selector_4_updating'";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM