Richzilla Posted May 11, 2007 Share Posted May 11, 2007 Hi all again, Sorry to ask but Ive spent all day on this and i still can't the bloody thing to add the ratings to the database. My page is now pretty complicated and i fear that it may be getting confused. Anyway here goes at an explaination - page - http://www.jungletekno.co.uk/ratings_page_halfway.php script at the top of the page - $var = @$_GET['q'] ; $trimmed = trim($var); $user="xxx"; $pass="xxx"; $host = "xxx"; $dbase="xxx"; $table = "Mixes"; mysql_connect($host,$user,$pass); if ( $mode=="vote") { $cookie = "jungletekno$id"; if(isset($_COOKIE[$cookie])) { Echo "Sorry You have already voted for that mix <p>"; } else { $month = 2592000 + time(); setcookie(Mysite.$id, Voted, $month); } $votes = $_POST['votes']; $mix = $_POST['m']; $query = "UPDATE Mixes SET total_votes = total_votes + '$votes', total_voted = total_voted + '1' WHERE id = $id"; @mysql_select_db($dbase) or die("Unable to select database"); $result=mysql_query($query); } $query = "SELECT * FROM Mixes WHERE dj LIKE '%$var%' OR rave LIKE '%$var%' OR tracklist LIKE '%$var%' OR date LIKE '%$var%' ORDER BY rave ASC"; @mysql_select_db($dbase) or die("Unable to select database"); $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> form for the rating - <form method="POST" action="<? echo $_SERVER['PHP_SELF'] ?>?mode=vote&m=<? echo $id ?>"> <p><select name="votes"> <option value="">Choose a Rating</option> <option value="5">I Love It!</option> <option value="4">Good</option> <option value="3">Moderate</option> <option value="2">Not Bad</option> <option value="1">Poor</option> </select><br /> <input type="submit" name="v_submit" value=" Rate It! " /></p> </form> Is the problem that I have 2 queries at the top of the page or is it that i have the syntax wrong where some commands should og later in the document? Everything works fine apart from the addition of ratings to the database. Any help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/50987-solved-fianl-part-of-my-voting-system-not-adding-to-the-database/ Share on other sites More sharing options...
kalivos Posted May 11, 2007 Share Posted May 11, 2007 I'm not sure if it is valid to put the 1 in single quotes. Try changing the following: $query = "UPDATE Mixes SET total_votes = total_votes + '$votes', total_voted = total_voted + '1' WHERE id = $id"; to this: $query = "UPDATE Mixes SET total_votes = total_votes + ".$votes.", total_voted = total_voted + 1 WHERE id = '$id'"; Your also missing the single quotes around $id. -Kalivos Quote Link to comment https://forums.phpfreaks.com/topic/50987-solved-fianl-part-of-my-voting-system-not-adding-to-the-database/#findComment-250895 Share on other sites More sharing options...
Richzilla Posted May 11, 2007 Author Share Posted May 11, 2007 Just tried all manner of different syntaxes for the line but none have worked. It appears that there are diffrent schools of through on how to write it. back to the drawing board ??? Quote Link to comment https://forums.phpfreaks.com/topic/50987-solved-fianl-part-of-my-voting-system-not-adding-to-the-database/#findComment-250912 Share on other sites More sharing options...
kalivos Posted May 11, 2007 Share Posted May 11, 2007 try adding after mysql_query: or die(mysql_error()) example: $result=mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/50987-solved-fianl-part-of-my-voting-system-not-adding-to-the-database/#findComment-250935 Share on other sites More sharing options...
Richzilla Posted May 11, 2007 Author Share Posted May 11, 2007 I've added it and also had a good play around with the code. I noticed that I wasn't taking the mix # from the url so i changed POST to GET but it still won't add the rating. This is so frustrating!!! Quote Link to comment https://forums.phpfreaks.com/topic/50987-solved-fianl-part-of-my-voting-system-not-adding-to-the-database/#findComment-250944 Share on other sites More sharing options...
Richzilla Posted May 12, 2007 Author Share Posted May 12, 2007 Having stripped down the whole lot ot the bear bones I've final found what i hope is the root of my problems - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' total_voted = total_voted + '1' WHERE id = ''' at line 1 I have changed the syntax to every possible permutation and it still has issues. He's the code (m=104 is a know file that I'm trying to use the code to increase through the ratings) - <? $user = "xxxx"; $pass = "xxxx"; $host = "xxxx"; $dbase = "xxxx"; $table = "Mixes"; mysql_connect($host,$user,$pass); $votes = $_POST['votes']; $mix = $_POST['m']; $new_total_voted = (total_voted + 1); $new_total_votes = (total_votes + $votes); $query = "UPDATE Mixes SET total_votes = $new_total_votes , total_voted = $new_total_voted WHERE id = $mix"; @mysql_select_db($dbase) or die("Unable to select database"); $result = mysql_query($query) or die(mysql_error()); mysql_close(); ?> <form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>?m=104"> <p><select name="votes"> <option value="">Choose a Rating</option> <option value="1">Poor</option> <option value="2">Not Bad</option> <option value="3">Moderate</option> <option value="4">Good</option> <option value="5">I Love It!</option> </select><br /> <input type="submit" name="v_submit" value=" Rate It! " /></p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/50987-solved-fianl-part-of-my-voting-system-not-adding-to-the-database/#findComment-251004 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.