cripin Posted May 15, 2013 Share Posted May 15, 2013 (edited) Hello, i added a vote button to my site (on local host still developing) it now appears on all rows basically as soon as the row gets created it appears, but the voting button only lets you vote for 1website, you can click any of them it takes you to the same page and when u enter and press vote the votes only add to one site, how can i make it so that the vote would add up to a specific site. I am guessing it should depend on an id but cant figure out how the query and code should look for this. As you can see it only votes for 1 because the id is set 1, how should i change it so that each topsite would have vote button with specific id? if(isset($_POST['code'])) { $vote_code = $_POST['code']; if(!empty($vote_code)) { $query = "SELECT count FROM users WHERE id=1"; if ($query_run = mysqli_query($con, $query)) { list($k) = mysqli_fetch_row($query_run); $jr = $k + 2; $voteup = "UPDATE users SET count ='$jr' WHERE id =1"; $updatevote = mysqli_query($con, $voteup); echo 'your vote has been added" "'; } }else{ echo 'hi'; } } Edited May 15, 2013 by cripin Quote Link to comment https://forums.phpfreaks.com/topic/278044-need-some-help-with-figuring-out-a-query-please/ Share on other sites More sharing options...
jazzman1 Posted May 15, 2013 Share Posted May 15, 2013 There are lots of errors in those queries. Take a look at php.net how to the mysqli_error() function. Quote Link to comment https://forums.phpfreaks.com/topic/278044-need-some-help-with-figuring-out-a-query-please/#findComment-1430314 Share on other sites More sharing options...
cripin Posted May 15, 2013 Author Share Posted May 15, 2013 no lol this script that i posted works, but it doesn't do what i want it to do, read my message next time before posting Quote Link to comment https://forums.phpfreaks.com/topic/278044-need-some-help-with-figuring-out-a-query-please/#findComment-1430319 Share on other sites More sharing options...
jazzman1 Posted May 16, 2013 Share Posted May 16, 2013 Hi cripin, sorry for that, just ignore it. I was very surprised when I saw that "COUNT" is NOT a reserved world in mysql. https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html Quote Link to comment https://forums.phpfreaks.com/topic/278044-need-some-help-with-figuring-out-a-query-please/#findComment-1430329 Share on other sites More sharing options...
Dathremar Posted May 16, 2013 Share Posted May 16, 2013 The $_POST['code'] can be your id field from the db, so add that to the query instead of the hardcoded id = 1. Also don't forget to clean and validate the $_POST param before using it inside a query. Quote Link to comment https://forums.phpfreaks.com/topic/278044-need-some-help-with-figuring-out-a-query-please/#findComment-1430373 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.