I have made a table ‘wp_mostfavourite’ in wordpress database, it has got three fields, ‘serialno’, ‘postid’, ‘counts’.
The ‘counts’ is supposeto 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);
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";
Even if I change $postids to any real value instead of GET request it works.
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.