pudge1 Posted August 6, 2010 Share Posted August 6, 2010 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; } Quote Link to comment https://forums.phpfreaks.com/topic/209981-voting-system-not-working/ Share on other sites More sharing options...
fenway Posted August 8, 2010 Share Posted August 8, 2010 TLDR... sounds like you have logic issues, not just mysql problems. Quote Link to comment https://forums.phpfreaks.com/topic/209981-voting-system-not-working/#findComment-1096651 Share on other sites More sharing options...
pudge1 Posted August 8, 2010 Author Share Posted August 8, 2010 What do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/209981-voting-system-not-working/#findComment-1096774 Share on other sites More sharing options...
fenway Posted August 10, 2010 Share Posted August 10, 2010 I mean those queries are fairly rudimentary, and I don't see how they couldn't work. So I suspect there's a php issue lurking. Quote Link to comment https://forums.phpfreaks.com/topic/209981-voting-system-not-working/#findComment-1097296 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.