Jump to content

Recommended Posts

  function Vote($note_id,$rating,$username)
   {
    $note_id = mysql_real_escape_string($note_id);
    $rating = mysql_real_escape_string($rating);
    $username = mysql_real_escape_string($username);

    $user_votes = file_get_contents('user/' . $username . '_votes.dat');
    $user_votes = explode(',',$user_votes);

     foreach($user_votes as $user_vote)
      {
       if($note_id == $user_vote)
        {
         return "False_1";
        }
       else
        {
        }
      }

    $user = '***';
    $pass = '***';
    $dbname = '***';

    $connection = mysql_connect('localhost',$user,$pass);

    mysql_select_db($dbname, $connection);

    $sql = "SELECT Votes FROM Notes WHERE Note_ID='$note_id'";
    $query = mysql_query($sql , $connection);

    $query2 = mysql_fetch_array($query);
    $query = $query2["Votes"];

    $query++;

    $sql = "UPDATE Notes SET Votes='$query' WHERE Note_ID='$note_id'";
    $query = mysql_query($sql , $connection);

    $sql = "SELECT * FROM Notes WHERE Note_ID='$note_id'";
    $query = mysql_query($sql , $connection);

    $query2 = mysql_fetch_array($query);
    $query = $query2["Total Rating"];

    $query = $query+$rating;

    $sql = "UPDATE Notes SET Total Rating='$query' WHERE Note_ID='$note_id'";
    $query = mysql_query($sql , $connection);

    $file = fopen('user/' . $username . '_votes.dat','a');
    fwrite($file,$note_id . ',');
    fclose($file);
   }

 

With the username I am using (user/pudge_votes.dat) the file is completely empty but for some reason it keeps returning False_1. I have no idea why it is doing this. Here is the page that the function is being used on. Also the database isn't updating like it should. It should get Votes from the table Notes where Note_ID=$note_id and increase its value by one and then update the vote count. Then it should get Total Rating from Notes where Note_ID=$note_id and add $rating to that value and then update the new value but neither of those are working either.

 

$vote = Vote($_POST['id'],$_POST['rating'],Get_Username());

  if($vote == 'False_1')
   {
    echo '<script>alert("You have already voted on this note. You may only vote once.' . $vote . '");</script>';
    echo '<meta http-equiv="refresh" content="0;URL=view_note.php?id=' . $_POST['id'] . '" />';
    exit;
   }
  else
   {
    echo '<script>alert("You have successfully voted on this note! Thank you for your contribution!");</script>';
    echo '<meta http-equiv="refresh" content="0;URL=view_note.php?id=' . $_POST['id'] . '" />';
    exit;
   }

Link to comment
https://forums.phpfreaks.com/topic/209981-voting-system-not-working/
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.