0

We have tried this way. But it is not working. please any one tell alternative method in wordpress

$wpdb->query("UPDATE ".$wpdb->prefix."recommend_bets SET `title`='".mysqli_real_escape_string($title)."',`category`='".$catID."',....
2
  • mysql_real_escape_string() used this instead of mysqli_real_escape_string()
    – Jenish
    Commented Mar 22, 2018 at 6:57
  • mysqli_real_escape_string() - not working @Jenish
    – Arun Kumar
    Commented Mar 22, 2018 at 6:58

2 Answers 2

4

When working with database in WordPress you should never use the low lever mysql_* or mysqli_* functions.

Always use $wpdb methods, in your case you should use prepare():

<?php
$wpdb->query( $wpdb->prepare( 
    "UPDATE ".$wpdb->prefix."recommend_bets
SET title = %s,
titleb = %s
WHERE ID = %d       
",
    'static', 'static2', 7
) );

// Or

$wpdb->update( 
    'table', 
    array( 
        'column1' => 'value1',  // string
        'column2' => 'value2'   // integer (number) 
    ), 
    array( 'ID' => 1 ), 
    array( 
        '%s',   // value1
        '%d'    // value2
    ), 
    array( '%d' ) 
);
?>
1
  • @YourCommonSense You cannot spell.
    – Strawberry
    Commented Mar 22, 2018 at 7:18
0

You can use wpdb::_real_escape( string $string ) function.

https://developer.wordpress.org/reference/classes/wpdb/_real_escape/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.