Jump to content

Boxerman

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/269373-basic-vote/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/269373-basic-vote/#findComment-1384706
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.