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
Share on other sites

$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 by ExtremeGaming
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.