Updating Wpdb via $ wpdb-> query () does not work

I am trying to make a wordpress plugin and I am having a problem.

The problem is with the update request, which I cannot understand why it does not work. The query should update the table without wordpress

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);

Help a little ?: (

+4
source share
1 answer

Try to execute the SQL query as follows: -

<?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 this works.

+8
source

Source: https://habr.com/ru/post/1535902/


All Articles