$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - wpdb Cannot Update column in Database|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - wpdb Cannot Update column in Database

matteradmin12PV0评论

In the custom table, I try to update a specific column with using $wpdb->update class and using HTML form for updating one column that has same id (in here dlname Is ID of data ).

The problem is this When I trying to update the column in my table using HTML form The page only will Refresh

BUT When I manually set ID in codes and THEN typing and submitting new value by HTML form it will work like charm.

It seems to be machine cannot understand the value that inputted from the form This is my code :

<?php
if(isset($_POST['btnUpdate'])){
    global $wpdb;
    $table_name='wp_AR_tb_name';

    $data_array = array(

    'dstatus' => $_POST['dstatuschange'],
    'downloadname' => $_POST['dlname'],

    );

    $data_where = array('downloadname' =>'dlname');
    $wpdb->update($table_name,$data_array,$data_where);
}

And this is my Form :

<form method="POST">

    <label> Input One : </label>
    <input type="text" name="dlname"/>

    <label> Input Two : </label>
    <input type="text" name="dstatuschange" />

    <button type="submit" name="btnUpdate"> Submit </button>
</form>

In the custom table, I try to update a specific column with using $wpdb->update class and using HTML form for updating one column that has same id (in here dlname Is ID of data ).

The problem is this When I trying to update the column in my table using HTML form The page only will Refresh

BUT When I manually set ID in codes and THEN typing and submitting new value by HTML form it will work like charm.

It seems to be machine cannot understand the value that inputted from the form This is my code :

<?php
if(isset($_POST['btnUpdate'])){
    global $wpdb;
    $table_name='wp_AR_tb_name';

    $data_array = array(

    'dstatus' => $_POST['dstatuschange'],
    'downloadname' => $_POST['dlname'],

    );

    $data_where = array('downloadname' =>'dlname');
    $wpdb->update($table_name,$data_array,$data_where);
}

And this is my Form :

<form method="POST">

    <label> Input One : </label>
    <input type="text" name="dlname"/>

    <label> Input Two : </label>
    <input type="text" name="dstatuschange" />

    <button type="submit" name="btnUpdate"> Submit </button>
</form>
Share Improve this question edited Feb 23, 2019 at 15:05 Jaydip Nimavat 2244 silver badges10 bronze badges asked Feb 23, 2019 at 12:28 TheXrionTheXrion 57 bronze badges 1
  • 1 What is data type of dlname in db? codex.wordpress/Class_Reference/wpdb#UPDATE_rows may help. Pay attension to format and where_format. – Qaisar Feroz Commented Feb 23, 2019 at 13:55
Add a comment  | 

1 Answer 1

Reset to default 1

First, an observation: the line highlighted below is correct as per your logic? This query will set the dstatus and downloadname fields in a row as $_POST['dstatuschange'] and $_POST['dlname'] if downloadname field is the 'dlname' string. Maybe you wanted to put the $_POST['dlname'] variable in your WHERE condition?

Second, wordpress custom POSTs work much better if you use the standard wordpress way to manage them. Look at this answer to see how to handle properly a custom form submission.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far