Boxerman Posted October 11, 2012 Share Posted October 11, 2012 Evening all, I've ran into a dead end, my php isnt the best. What i am trying to do is get a simple voting script working. User clicks vote up.. it updates the table +1 user votes down -1. Simple enough. However this is what i have so far... <?php if(isset($_POST['voteup'])) { $sql = "UPDATE movies SET ratings = increment + 1 WHERE id = '".$_GET['id']."'"; mysql_query($sql); } ?> <a href="?voteup">VOTE UP</a> | <a href="?votedown">VOTE DOWN</a> <?php if(isset($_POST['votedown'])) { $sql = "UPDATE movies SET ratings = increment - 1 WHERE id = '".$_GET['id']."'"; mysql_query($sql); } ?> Error i get is: Parse error: syntax error, unexpected T_STRING on line 23 As you can see there is only 15 lines here? Extra info: the page is called watch.php?id=15 vote will be near bottom of page. table has a column called ratings set as INT (32) If you need anything else please let me know! Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 11, 2012 Share Posted October 11, 2012 (edited) If there is an error associated with line 23, you are not showing all the code. Please show the full error as well Edited October 11, 2012 by ExtremeGaming Quote Link to comment Share on other sites More sharing options...
Boxerman Posted October 11, 2012 Author Share Posted October 11, 2012 (edited) I copied this to a blank page test.php and that is the error.. thats the only code on that page. Parse error: syntax error, unexpected T_STRING in C:\Inetpub\vhosts\******\httpdocs\test.php on line 23 Edited October 11, 2012 by Boxerman Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 11, 2012 Share Posted October 11, 2012 (edited) $sql = "UPDATE movies SET ratings = increment + 1 WHERE id = '".$_GET['id']."'"; First, you should have that in single quotes after set ratings, and increment is not doing anything which is most likely the source of your error Edited October 11, 2012 by ExtremeGaming Quote Link to comment Share on other sites More sharing options...
Boxerman Posted October 11, 2012 Author Share Posted October 11, 2012 Sorry I don't understand? This script is standalone, no other pages are included (the db connection details are missing i know). Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 12, 2012 Share Posted October 12, 2012 In your code, increment is not defined. It's not even used as a variable. Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 12, 2012 Share Posted October 12, 2012 Why are you doing ratings = increment + 1 is the question? What is increment supposed to be? A column or a variable? Quote Link to comment Share on other sites More sharing options...
kicken Posted October 12, 2012 Share Posted October 12, 2012 The code you posted, when run through a syntax check yields No syntax errors detected in - so there is nothing wrong syntax-wise with that code block. Either there is more to the file than you are showing, or you're server is doing something to modify the file before processing it and is causing a problem. Do you get the same error if you change the code around some, such as merging the PHP blocks together and putting the html at the end?: <?php if(isset($_POST['voteup'])) { $sql = "UPDATE movies SET ratings = increment + 1 WHERE id = '".$_GET['id']."'"; mysql_query($sql); } else if(isset($_POST['votedown'])) { $sql = "UPDATE movies SET ratings = increment - 1 WHERE id = '".$_GET['id']."'"; mysql_query($sql); } ?> <a href="?voteup">VOTE UP</a> | <a href="?votedown">VOTE DOWN</a> Also, as has been pointed out, ratings = increment + 1 does not make sense. ratings = ratings + 1 is probably what you want. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 12, 2012 Share Posted October 12, 2012 <a href="?voteup"> As voteup is in the querystring, use $_GET and not $_POST Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.