I'm using ajax to send a vote_status
URL parameter to a script which updates my db table.
It inserts data but for example if vote_status=up
I get this notice.
Use of undefined constant up - assumed 'up'
and if vote_status=down
I get
Use of undefined constant up - assumed 'up'
Use of undefined constant down - assumed 'down'
Below is part of the开发者_如何学JAVA script on which I get notices.
$vote_status = $_POST['vote_status'];
switch ($vote_status)
{
case up:
$wpdb->query( $wpdb->prepare( "UPDATE wp_posts SET up=up+1 WHERE post_id = $vote_post_id" ) );
echo "Up Added!";
break;
case down:
$wpdb->query( $wpdb->prepare( "UPDATE wp_posts SET down=down+1 WHERE post_id = $vote_post_id" ) );
echo "Down Added!";
break;
case block:
echo "Already Voted!";
break;
}
I'm not sure how to fix this. The script looks fine to me..
Enclose the words "up", "down" and "block" in quotes. Currently, PHP is interpreting them as constants.
case "up":
...
case "down":
...
case "block":
...
精彩评论