• I have made a table ‘wp_mostfavourite’ in wordpress database, it has got three fields, ‘serialno’, ‘postid’, ‘counts’.

    The ‘counts’ is supposed to increased by 1, whenever the following query is processed.

    $postids = $_GET['action']; // I tried stripslashes($_GET['action']) as well, the query is not working
    
    $querycount="update wp_mostfavourite set counts = counts+1 where postid = $postids";
    
    $wpdb->query($querycount);

    But after running, this query changes the value of counts for the particular postid in the table to 1, no matter if I write counts = counts+1 or counts = counts+ 5

    if I put the value of postid in the where clause directly it works.

    $querycount="update wp_mostfavourite set counts = counts+1 where postid = 72270";

    Or if I change $postids to any real value instead of GET request it works.

    $postids=72270;

    I even tried $wpdb->prepare, but still facing the same issue

    $wpdb->query( $wpdb->prepare(
    "
        update wp_mostfavourite
        set counts = counts+%d
            where postid= %d
    
    ",
    1,
    $postids // the query is working when I replace it with values such as 72270
    ) );

    Any possible suggestions will be appreciated.

Viewing 1 replies (of 1 total)
  • Thread Starter anonimous98

    (@anonimous98)

    I don’t know how the title got cut and I can’t even edit it… so the complete Title is


    $wpdb->query(update table) not working as supposed when passing GET request in the where clause

Viewing 1 replies (of 1 total)
  • The topic ‘$wpdb->query(update table) not working as supposed when passing GET request in t’ is closed to new replies.