mat-tastic Posted February 12, 2009 Share Posted February 12, 2009 in Progress. I made a cock up with the original post, I will repost it. Quote Link to comment https://forums.phpfreaks.com/topic/144955-phpmysql-help-with-weird-numbers/ Share on other sites More sharing options...
gizmola Posted February 12, 2009 Share Posted February 12, 2009 There is no reason to grab the vote count, when SQL already solves this problem for you. Try this: UPDATE screenshots SET votes = votes +1 WHERE id = '$id' Quote Link to comment https://forums.phpfreaks.com/topic/144955-phpmysql-help-with-weird-numbers/#findComment-760651 Share on other sites More sharing options...
mat-tastic Posted February 12, 2009 Author Share Posted February 12, 2009 Thanks Gizmola However I have tried this: if (isset($_GET['vote'])) { $id = $_GET['id']; $addvotesql = "UPDATE screenshots SET votes = votes + 1 WHERE id = '$id'"; mysql_query($addvotesql, $conn_abrv) or die(mysql_error()); // add the vote } Now nothing is happening! Quote Link to comment https://forums.phpfreaks.com/topic/144955-phpmysql-help-with-weird-numbers/#findComment-760701 Share on other sites More sharing options...
marcus Posted February 12, 2009 Share Posted February 12, 2009 Try echoing something after your query. "nothing is happening" can be referred to as nothing is showing up on the page, or the votes aren't increasing, etc... Quote Link to comment https://forums.phpfreaks.com/topic/144955-phpmysql-help-with-weird-numbers/#findComment-760704 Share on other sites More sharing options...
mat-tastic Posted February 12, 2009 Author Share Posted February 12, 2009 Ok, now it is adding something, however it is adding two instead of one: if (isset($_GET['vote'])) { $id = $_GET['vote']; echo $id; $addvotesql = "UPDATE screenshots SET votes = votes + 1 WHERE id = '$id'"; mysql_query($addvotesql, $conn_abrv) or die(mysql_error()); // addd the vote } Quote Link to comment https://forums.phpfreaks.com/topic/144955-phpmysql-help-with-weird-numbers/#findComment-760705 Share on other sites More sharing options...
gizmola Posted February 12, 2009 Share Posted February 12, 2009 If that's true then I would think there is a logic error in your scripts where the query is being run 2x rather than once. Quote Link to comment https://forums.phpfreaks.com/topic/144955-phpmysql-help-with-weird-numbers/#findComment-760732 Share on other sites More sharing options...
mat-tastic Posted February 12, 2009 Author Share Posted February 12, 2009 If that's true then I would think there is a logic error in your scripts where the query is being run 2x rather than once. I don't see how it would be running twice. Here is the whole lot: ( I can't see anywhere that would cause it to re run the page. <? include "config.php"; mysql_select_db($database_conn, $conn_abrv); $screenshots = "SELECT * FROM screenshots"; $screenshots_query = mysql_query($screenshots, $conn_abrv) or die(mysql_error()); $totalrows_screenshots = mysql_num_rows($screenshots_query); $row_screenshots = mysql_fetch_assoc($screenshots_query); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" /> <title>The American Pacific Group | Virtual Airlines</title> <link href="http://apg.flyafa.com/style.css" type="text/css" rel="stylesheet"> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-655677-1"; _udn="flyafa.com"; urchinTracker(); </script> <script type="text/javascript"> <!-- function fPopWindow(url) { window.open(url, "myWindow", "location = 0, status = 1, fullscreen=1, scrollbars = 1, resizable = 1" ) } //--> </script> <style type="text/css"> <!-- .style1 { font-size: 14pt; font-weight: bold; } .style3 { font-size: 10pt } .style4 {font-size: 12pt} --> </style> </head> <body bgcolor="#FFFFFF" topmargin="0" marginheight="0" leftmargin="0" rightmargin="0" marginwidth="0"> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="10"><br> <table cellspacing="0" cellpadding="0" width="100%"><tr><td> <img src="http://apg.flyafa.com/images/top_lt_lg.gif"></td><td background="http://apg.flyafa.com/images/top_liner.gif" width="100%"> </td><td><img src="http://apg.flyafa.com/images/top_rt_lg.gif"></td></tr></table><img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="5"><br> <table width="98%" align="center"><tr><td valign="top" width="20%" align="center"> <table width="160" border="0" cellpadding="0" cellspacing="0"><tr><td align="left" width="15"><img src="http://apg.flyafa.com/images/nav_top_lt.gif"></td><td background="http://apg.flyafa.com/images/nav_top.gif"><img src="http://apg.flyafa.com/images/clearpixel.gif" width="0" height="0"></td><td align="right" width="15"><img src="http://apg.flyafa.com/images/nav_top_rt.gif"></td></tr><tr><td align="left" background="http://apg.flyafa.com/images/nav_lt.gif" width="15"><img src="http://apg.flyafa.com/images/clearpixel.gif" width="0" height="0"></td> <td> » <a href="http://apg.flyafa.com">Front Page</a><br> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br> » <a href="http://apg.flyafa.com/airlines.php">Member Airlines</a><br> » <a href="http://apg.flyafa.com/india">APG India</a><br><img src=""http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br>» <a href="http://www.flyafa.com/hub.php?id=8">AFA Australia</a><br><img src=""http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br> » <a href="http://apg.flyafa.com/filelib.php">File Library</a><br> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br> » <a href="http://apg.flyafa.com/news_atis.php">News ATIS</a><br> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br> » <a href="http://apg.flyafa.com/weather.php">Weather Center</a><br> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br> » <a href="http://forums.flyafa.com">Message Board</a><br> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br> » <a href="http://apg.flyafa.com/events.php">VATSIM Events</a><br> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br> » <a href="http://apg.flyafa.com/training">Training Division</a><br> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br> » <a href="http://apg.flyafa.com/charter">Charter Flights</a><br> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="1"><br> » <a href="http://apg.flyafa.com/ss">Screenshot Gallery</a><br> <img src="http://apg.flyafa.com/images/clearpixel.gif" width="1" height="5"><br> </td><td align="left" background="http://apg.flyafa.com/images/nav_rt.gif" width="15"><img src="http://apg.flyafa.com/images/clearpixel.gif" width="0" height="0"></td></tr> <tr><td align="left" width="15"><img src="http://apg.flyafa.com/images/nav_m_lt.gif"></td><td background="http://apg.flyafa.com/images/nav_m.gif"><img src="http://apg.flyafa.com/images/clearpixel.gif" width="0" height="0"></td><td align="right width="15"><img src="http://apg.flyafa.com/images/nav_m_rt.gif"></td></tr> <tr><td align="left" background="http://apg.flyafa.com/images/nav_lt.gif" width="0"><img src="http://apg.flyafa.com/images/clearpixel.gif" width="0" height="0"></td><td> <table align="center"><form method="post" action="http://prs.flyafa.com/pirep.php" enctype="application/x-www-form-urlencoded"> <input type="hidden" name="action" value="login"> <tr><td>Pilot ID:</td><td><input type="text" name="pid" size="8" maxlength="7"></td></tr><tr><td>Password:</td><td><input type="password" name="pass" size="8" maxlength="30"></td></tr><tr><td colspan="2" align="right"><input type="submit" name="submit" value="Login"></td></form></tr></table> </td><td align="right" background="http://apg.flyafa.com/images/nav_rt.gif"><img src="http://apg.flyafa.com/images/clearpixel.gif" width="0" height="0"></td></tr> <tr><td align="left" width="15"><img src="http://apg.flyafa.com/images/nav_bottom_lt.gif"></td><td background="http://apg.flyafa.com/images/nav_bottom.gif"><img src="images/clearpixel.gif" width="0" height="0"></td><td align="right" width="15"><img src="http://apg.flyafa.com/images/nav_bottom_rt.gif"></td></tr> </table> </td> <td valign="top" width="90%"> <a href="http://apg.flyafa.com">American Pacific Group</a> » <a href="screenshot-voting.php">Screenshot Voting System</a> <p> <p> <p> <table width="500"><tr><td><p align="center" class="style1">APG Screenshot Voting System <p><? if (isset($_GET['vote'])) { $id = $_GET['vote']; echo $id; $addvotesql = "UPDATE screenshots SET votes = votes + 1 WHERE id = '$id'"; mysql_query($addvotesql, $conn_abrv) or die(mysql_error()); // addd the vote } // record there IP, set a session. The session won't do much, all they have to do is restart there browser, however most cannot cahnge there ip, but again, some can. This effors to stop cheating are futile, if they want to cheat they will find a way round it. Oh well. Some defence is better then none. /* $ip=$_SERVER['REMOTE_ADDR']; $sql_ip = "INSERT INTO anticheat (voteid, ip) VALUES ('$id' , '$ip')"; $result_ip = mysql_query($sql_ip, $conn_abrv) or die(mysql_error()); $_SESSION['voted']; echo "Thank you, your vote has been recorded <br><br> If you feel you have made a mistake, then please go <b><a href = \"change.php\">HERE</a></b><br><br><br>"; exit; */ if($totalrows_screenshots < 1) { echo "No Screenshots have been added for this months compitition yet, please check back soon!"; } ?>Welcome to the AFA Screenshot Voting System, where you can vote for the best screenshot every month.</p> <p>Every month a selection of the best rated screenshots will be put here for you to vote. You are only allowed to vote once.</p> <p>If you have made a mistake in your voting, please click the link displayed once you have voted or <a href="screenshot-voting.php?mistake">click here</a></p> <p align="center"><strong><span class="style4">Screenshots for September</span></strong></p> <? do { ?> <p align="center"><strong>Title: </strong><? echo $row_screenshots['title']; ?> </p> <p align="center"><strong>Description: </strong><? echo $row_screenshots['description']; ?> </p> <p align="center"><a href="screenshot-voting.php?vote=<? echo $row_screenshots['id']; ?>"><img src="<? echo $row_screenshots['url']; ?>" width="640" height="446"></a><br><br><br><br><br> <? } while ($row_screenshots = mysql_fetch_assoc($screenshots_query)); ?> </p> <p align="center" class="style3"> <p align="left"> <p align="left"> <p align="center"><strong></strong></td> </tr></table></td></tr></table> </td></tr></table> <center><font face="verdana" size="-2">Copyright © 2002-2008, The American Pacific Group. All rights reserved.</font></center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/144955-phpmysql-help-with-weird-numbers/#findComment-760738 Share on other sites More sharing options...
mat-tastic Posted February 12, 2009 Author Share Posted February 12, 2009 Any ideas anyone? Really confusing me this one. Quote Link to comment https://forums.phpfreaks.com/topic/144955-phpmysql-help-with-weird-numbers/#findComment-760834 Share on other sites More sharing options...
samshel Posted February 12, 2009 Share Posted February 12, 2009 try echoing the query $addvotesql = "UPDATE screenshots SET votes = votes + 1 WHERE id = '$id'"; Quote Link to comment https://forums.phpfreaks.com/topic/144955-phpmysql-help-with-weird-numbers/#findComment-760840 Share on other sites More sharing options...
gizmola Posted February 13, 2009 Share Posted February 13, 2009 I don't see anything off the top of my head, but I also don't know what's in your database initially. Are you sure that the value of votes in the screenshot table is 0 when you start and not 1? Quote Link to comment https://forums.phpfreaks.com/topic/144955-phpmysql-help-with-weird-numbers/#findComment-761002 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.