I need to update the database with a request from ajax, only when I write this code, I do not update the database
global $wpdb;
if ( isset( $_POST['edit_row'] ) ){
$wpdb->update( 'wp_rel_eq', array(
'id'=>$_POST['row_id'],
'title' => $_POST['title_val'],
'anonce' => $_POST['anonce_val'],
'url' => $_POST['url_val'],),
array( '%s', '%s', '%s', '%s')
);
echo mysql_insert_id();
exit();
As per documentation of wordpress
<?php $wpdb->update( $table, $data, $where, $format = null, $where_format = null ); ?>
As per your code you missed third parameter which is $where
Examples Update a row, where the ID is 1, the value in the first column is a string and the value in the second column is a number:
$wpdb->update(
'table',
array(
'column1' => 'value1', // string
'column2' => 'value2' // integer (number)
),
array( 'ID' => 1 ),
array(
'%s', // value1
'%d' // value2
),
array( '%d' )
);
documentation Ref: https://codex.wordpress.org/Class_Reference/wpdb
if i split your code then
$table
will be
wp_rel_eq
$data
will be
array(
'id'=>$_POST['row_id'],
'title' => $_POST['title_val'],
'anonce' => $_POST['anonce_val'],
'url' => $_POST['url_val'],)
$where
not passed
$format will be
array( '%s', '%s', '%s', '%s')