I have this code:
add_action( 'delete_post', 'my_delete_function' );
function my_delete_function($post_id) {
global $wpdb;
$achievement = get_the_category($post_id);
$h = $achievement[0]->cat_ID;
$s = ''.str_replace('"', '', $h);
$p = var_dump(htmlentities($s));
$wpdb->query("INSERT INTO ".$wpdb->prefix."votes (post, votes, guests, usersinks, guestsinks) VALUES('', ".$p.", '', '', '') ") or die(mysql_error());
}
mySQL keeps throwing this error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '', '', '')' at line 1
Ive ran the same query in phpMyAdmin, replacing the php vars with values and it works fine
Additionally, ive made sure the the value of $s is just a number by using the echo function on a blank page.
Any help is appreciated
If you want to get the last error and last query you can use this properties of $wpdb object:
will show you the last error, if you got one.
will assist you with showing the last query (where the error occurred)
I hope this will help you out.
maybe
$wpdb->query("INSERT INTO ".$wpdb->prefix."votes (post, votes, guests, usersinks, guestsinks) VALUES('', '".$s."', '', '', '') ") or die(mysql_error());
My guess is that the $s is empty and the SQL query ends up looking like this:
Why are you doing
Is it actually possible that the int contains an “? This is not nice. But I’d eventually do this
to ensure that the variable is an int – no matter what.
Try this:
If that doesn’t work then you are probably leaving blank fields that require a value.