Wpdb update via $wpdb->query() not working

14,439

Try SQL Query like this:-

<?php 
global $wpdb;
$sql ="UPDATE $lmdisp_table_name
    SET `".$lmdisp_nume."`= '".$nume."',
    `".$lmdisp_departament."` = '".$dep."',
    `".$lmdisp_an."` = '".$an."',
    `".$lmdisp_grupaserie."` = '".$grupa."',
    `".$lmdisp_tel."` = '".$tel."' ,
    `".$lmdisp_email."` = '".$email."',
    `".$lmdisp_fb."` = '".$fb."',
    `".$lmdisp_tw."` = '".$tw."',
    `".$lmdisp_linked."` = '".$linked."',
    `".$lmdisp_freel."` = '".$freel."',
    `".$lmdisp_blog."` = '".$blog."',
    `".$lmdisp_memyear."` = '".$memyear."',
    `".$lmdisp_fctlse."` = '".$fct."',
    `".$lmdisp_evlse."` = '".$evlse."',
    `".$lmdisp_skills."` = '".$skills."',
    `".$lmdisp_avatar."` = '".$avatar."',
    `".$lmdisp_cv."` = '".$cv."'
WHERE  `".$lmdisp_id."` = '".$id."'";

$rez = $wpdb->query($sql);

Hope it will work.

Share:
14,439

Related videos on Youtube

Andrei Terecoasa
Author by

Andrei Terecoasa

By day: full time employee Rest of my time: having fun, watching movies, coding, trying new things ^^

Updated on June 04, 2022

Comments

  • Andrei Terecoasa
    Andrei Terecoasa almost 2 years

    I'm trying to make a wordpress plugin and i came over a problem.

    The problem is with an update query which i can't figure out why it isn't working. The query should update a non wordpress table

    global $wpdb;
    $sql ="UPDATE $lmdisp_table_name
                SET `".$lmdisp_nume."`=".$nume.",
                    `".$lmdisp_departament."` = ".$dep.",
                    `".$lmdisp_an."` = ".$an.",
                    `".$lmdisp_grupaserie."` = ".$grupa.",
                    `".$lmdisp_tel."` = ".$tel."' ,
                    `".$lmdisp_email."` = ".$email.",
                    `".$lmdisp_fb."` = ".$fb.",
                    `".$lmdisp_tw."` = ".$tw.",
                    `".$lmdisp_linked."` = ".$linked.",
                    `".$lmdisp_freel."` = ".$freel.",
                    `".$lmdisp_blog."` = ".$blog.",
                    `".$lmdisp_memyear."` = ".$memyear.",
                    `".$lmdisp_fctlse."` = ".$fct.",
                    `".$lmdisp_evlse."` = ".$evlse.",
                    `".$lmdisp_skills."` = ".$skills.",
                    `".$lmdisp_avatar."` = ".$avatar.",
                    `".$lmdisp_cv."` = ".$cv."
               WHERE  `".$lmdisp_id."` = ".$id."";
    
        $rez = $wpdb->query($sql);
    

    A little help ?:(

    • Akshay Paghdar
      Akshay Paghdar about 10 years
      Double Check your variables of table field name with db table fields.
    • Andrei Terecoasa
      Andrei Terecoasa about 10 years
      Double checked. Also other functions are working as expected!:)
  • Andrei Terecoasa
    Andrei Terecoasa over 8 years
    forgot to say thanks. well...i guess.. it's never too late! thanks.
  • Brian C
    Brian C about 3 years
    a random thought - might be worth using $wpdb->update(...) instead of this. If nothing else, it would make the presently very unsafe solution into an injection-proof solution.