PHP - Google Voting And Clicking On Pages
I made a website for school where everyone can upload their summaries, download them and rate them (thumbs up, thumbs down).
You upload a summary with some data: a specific class, subject, name etc. The path to the file, the name, subject etc. comes in a mysql table and the summaries show in a list on the site. Now here comes the problem, when you vote a summary up you go to the page up.php like this: Code: [Select] <!--Directing to up.php--> --some mysql-- while ( $summary = mysql_fetch_assoc($result) ) { echo "<a href=\"up.php?id=".$summary['id']."&page=".$summary['class'].$summary['period']."\">"; } On the page up.php I have the following code which adds +1 in the thumbsup row in myqsl: Code: [Select] <!-- thumbsup +1 --> --some mysql-- $sql2 = "UPDATE locatie SET thumbsup = thumbsup + '1' WHERE id='".strval($_GET['id'])."'"; $uitvoeren2 = mysql_query($sql2); and sends you back to the previous page Code: [Select] header("Location: ".$_GET['page'].".php"); Google crawls all my pages, and also the page Code: [Select] up.php?id=1&page=class1periode3, which changes my mysql. Leading to that all of the summaries are being voted on by google, which is every annoying. This probably isn't the best voting script but I'm fairly new to php and thought this up on my own, so I was wondering if I could get it working properly Thanks in advance Similar TutorialsNot sure if this is possible, but.. As most of you likely know, if a person searches Google, they can see how many webpages are indexed by using: site:techcrunch.com Is there any way that I could do this via a php script for 10 different sites and then have the results emailed to me on a daily basis? I'm not asking for a coded solution.. just an idea on how this might be achieved, if it could? Thanks. Hello, I was wondering is it possible to create vote with php when people vote the voted thing will go away like for exsample if there is ingame map vote and players vote !map de_dust2 the de_dust2 will be removed from map list and the last map that stays will be used? Sorry for bad english. <form action='index.php' method='POST' enctype='multipart/form-dat'> <select name='votes'> <option>SEATOWN</option> <option>vote1</option> <option>vote2</option> <option>vote3</option> </select> <input type='submit' name='vote' value='Vote'> </form> <?php $vote=$_GET['votes']; if(isset($_POST['vote'])) { echo "voted"; echo $vote; } ?> why would this not echo out anything for $vote??? cheers matt Hi, I am trying to come up with the best way to create a range voting form. Each candidate will have a "confidence" value associated with the choice.(using a pulldown menu?) So for March Madness it would be: Team ....... Confidence Value..... each team could only be voted to finish the tournament in a particular place, and a value would be associated with that choice. The total choices possible determines the range of confidence value possible. So....if there are 16 teams to vote on....the confidence value would range from 1-16. The voter would assign his highest available value to the team he was most confident in landing in that particular position. Example: 16 teams - 16 conf vals - if certain Duke will end up at #1 - then vote : #1 = Duke, conf val 16 next, if almost as certain that NC will end up last - then vote: #16 = NC, conf val 15 next most certain "", conf val 14 and so on.... the tricky part is making sure that the form code validates each conf val so that it is used, but used on ly once.... ideally the form could return values that could then be imported into excel and comopared. has this been done somewhere? Can you help ? hope so.... thanks!! I'm trying to make a voting system, Where each person would vote and they'll receive a point for it. I just don't know how to accomplish this.. =/ This is a node voting module I created and it has a slight problem that I cannot figure out. It's supposed to be a simple 'Vote Up' or 'Vote Down' feature. You click 'Vote Up' and one appears in your vote tally. You click 'Vote Down' and your original vote tally is subtracted by one back down to zero. When it goes back to zero, it gets stuck there. It stays on zero no matter if I choose 'Vote Up' or 'Vote Down' again. There's something that's happening when I move my vote tally back down to zero. Maybe something isn't setup correctly with the $current_votes variable. I don't know. I've been at this for hours. Here's the code: <?php function bonnier_vote_perm() { return array('vote on content'); } function bonnier_vote_menu() { $items = array(); $items['vote'] = array( 'title' => 'vote', 'page callback' => 'bonnier_vote_vote', 'access arguments' => array('vote on content'), 'type' => MENU_CALLBACK, ); return $items; } function bonnier_vote_vote() { $nid = $_REQUEST['nid']; $value = $_REQUEST['votes']; $current_votes = db_result(db_query("SELECT votes FROM bonnier_vote WHERE nid = $nid")); if ($current_votes) { $new_votes = $current_votes + $value; db_query("UPDATE bonnier_vote SET votes = $new_votes WHERE nid = $nid"); } else { db_query("INSERT INTO bonnier_vote (nid, votes) VALUES ($nid, $value)"); } drupal_set_message('Your vote has been recorded'); drupal_goto('node/'.$nid); } function bonnier_vote_nodeapi(&$node, $op, $teaser = null, $page = null) { if ($op == 'view' && !$teaser) { $votes = db_result(db_query("SELECT votes FROM bonnier_vote WHERE nid = {$node->nid}")); if (!$votes) { $votes = 0; } $widget = '<div>'; $widget .= l('Vote Up', 'vote', array('query' => array('nid' => $node->nid, 'votes' => 1))); $widget .= ' '; $widget .= l('Vote Down', 'vote', array('query' => array('nid' => $node->nid, 'value' => -1))); $widget .= ' '; $widget .= 'Sco '. $votes; $widget .= '</div>'; $node->content['vote_widget'] = array( '#value' => $widget, '#weight' => -10, ); } } Any bit of advice would be much appreciated. Basically I am writing my own voting system but I have a few problems and I would like to address them all in one post rather than three. First: The first thing I need help with is using CURL to check if a user actually voted at the remote top list website. Two: I need maybe a source script of a 10 digit hash generator that will display the hash generated and will insert it into the database This is currently what my hash generator looks like but I need someone to help me change it so that it will echo the actual hash generated and inserts it into the database, <?php function gen_md5_password($len = 6) { return substr(md5(rand().rand()), 0, $len); } ?> Three: I need some sort of way to tell the database that if they hash is not used within 24 hours, it will just dump or delete. hi guys i am building a voting system for my gaming website people sign up for matches, and those will be played at 3-5 different maps people can vote for wich maps they want to play each player can choose 3 maps, also 3 x the same map now the results of that voting system are shown on the page like this There is 1 vote for Map 1 There are 5 votes for Map 2 There is 1 vote for Map 3 There are 2 votes for Map 7 There is 1 vote for Map 4 There is 1 vote for Map 5 There are 8 votes for Map 8 now i want to make a script that picks the maps that will be played, so only show the 3-5 best results in the example above it woud be 2 x map 8 and 1x map 2 but im not sure how to start on this the db table of the votes is built like this id matchid playerid mapid mapname 1 113 195 1 NukeTown 2 113 195 2 Grid 3 113 195 1 NukeTown 4 114 195 1 NukeTown 5 114 195 1 NukeTown any advice or thoughts on this? thanks So I have made an anonymous poll system but I would like to limit the possibility to vote only once from a single pc. I think that I could store and check 3 things regarding a user that has voted: 1) $_SERVER['HTTP_CLIENT_IP']."!".$_SERVER['HTTP_X_FORWARDED_FOR']."!".$_SERVER['REMOTE_ADDR']; 2) HTTP cookie 3) Flash cookie LSO (because this contrary to the HTTP cookei can be detected in multiple browsers( (only if Flash is installed))) But there can be a simple situation - a simple user votes one time from Firefox and after a time his IP changes (for example he uses some Mobile internet where dynamic addressing is used) . Then for some reason he wants to use Internet Explorer where Flash is not installed. In result - it is possible to vote twice. Can anyone please suggest something regarding this? I know there is not 100% bulletproof solution - I just want to minimise the possibility to vote more than once. Also I am thinking about using EverCookie(undeletable cookie) but that could cause a lot of other problems. Hi there, im hoping someone can help me with this. What i’m trying to do is prevent users from voting twice with cookies, ive tried to set several myself but none of them have worked. Any help would be amazing. Thanks. EDIT: unsure why its formatted this way. how to fix?
<?php include 'functions.php'; // Connect to MySQL $pdo = pdo_connect_mysql(); // If the GET request "id" exists (poll id)... if (isset($_GET['id'])) { // MySQL query that selects the poll records by the GET request "id" $stmt = $pdo->prepare('SELECT * FROM polls WHERE id = ?'); $stmt->execute([$_GET['id']]); // Fetch the record $poll = $stmt->fetch(PDO::FETCH_ASSOC); // Check if the poll record exists with the id specified if ($poll) { // MySQL query that selects all the poll answers $stmt = $pdo->prepare('SELECT * FROM poll_answers WHERE poll_id = ?'); $stmt->execute([$_GET['id']]); // Fetch all the poll anwsers $poll_answers = $stmt->fetchAll(PDO::FETCH_ASSOC); // If the user clicked the "Vote" button... if (isset($_POST['poll_answer'])) { // Update and increase the vote for the answer the user voted for $stmt = $pdo->prepare('UPDATE poll_answers SET votes = votes +1 WHERE id = ?'); $stmt->execute([$_POST['poll_answer']]); // Redirect user to the result page header ('Location: result.php?id=' . $_GET['id']); exit; } } else { die ('Poll with that ID does not exist.'); } } else { die ('No poll ID specified.'); } ?> <?=template_header('Poll Vote')?> <div class="content poll-vote"> <h2><?=$poll['title']?></h2> <p><?=$poll['des']?></p> <form action="vote.php?id=<?=$_GET['id']?>" onSubmit="disable()" method="post"> <?php for ($i = 0; $i < count($poll_answers); $i++): ?> <label> <input type="radio" name="poll_answer" value="<?=$poll_answers[$i]['id']?>"<?=$i == 0 ? ' checked' : ''?>> <?=$poll_answers[$i]['title']?> </label> <?php endfor; ?> <div> <input type="submit" name="submit" value="Vote"> <a href="result.php?id=<?=$poll['id']?>">View Result</a> </div> </form> </div> <?=template_footer()?> Edited July 1, 2020 by requinix cleaning up post Hello, Im trying to create a simple voting script for my site, i been trying different things but cannot get it too function properly. The idea is you click the 'thumbs up' image to add 1 to the 'likes' value and thumbs down to add '1' to the dislikes. Sound simple but its giving me headaches. Would really appreciate it if someone could take a quick look at my script. The table is called 'youtube_rating' (because thats the look i was going for) and in the table is 4 columns, id (aut0_increment), liked (counts liked votes), disliked (counts dislikes) and item_num which is the id for teh product the rating is for. Code: [Select] <? if ( $row['rating'] == 'YES' ) { require ("../rating/voting/dbcon.php"); $result1 = mysql_query("select * from youtube_rating WHERE item_num='".$page_id."'"); $row = mysql_fetch_array($result1); $dislike = $row['dislike']; $like = $row['liked']; if (isset($_POST['submitted'])) { require_once ("../database/functions.php"); $userip = $_SERVER['REMOTE_ADDR']; $id = safe($_POST['id']); $vote = '1'; // check if user already voted $result = mysql_query("SELECT * FROM youtube_ip WHERE userip='$userip' AND item_num ='".$id."'"); $num = mysql_num_rows($result); // if already voted show error if (isset($_POST['submitted']) && ($num > 0)) { echo '<div class="alreadyvoted">You have already voted!</div>'; } // add like if (isset($_POST['submitted']) && ($_POST['submitted'] == 'like') && ($num == 0)) { // add 1 to value $liked_value = mysql_query("SELECT liked FROM youtube_ip WHERE item_num ='".$id."'"); $liked_total = $liked_value + $vote; $query = "update youtube_rating set liked = '".$liked_total."' where item_num ='".$id."'"; echo '<div class="ilikethis">You like this!</div>'; } // add dislike if (isset($_POST['submitted']) && ($_POST['submitted'] == 'dislike') && ($num == 0)) { // add 1 to value $dislike_value = mysql_query("SELECT dislike FROM youtube_ip WHERE item_num ='".$id."'"); $dislike_total = $dislike_value + $vote; $query = "update youtube_rating set dislike = '".$dislike_total."' where item_num ='".$id."'"; echo '<div class="idislikethis">You Dislike this!</div>'; } // log ip // if (isset($_POST['submitted']) && ($num == 0)) // { // mysql_query ("insert into youtube_ip (userip, item_num) values ('".$userip."', '".$id."')"); // } } ?> <table width="50%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="48%" align="center"> <form action="" method="post"> <input name="id" type="hidden" value="<? echo $page_id ?>" /> <input name="submitted" type="hidden" value="like" /> <button type="submit" class="like_button" name="like" id="like" > <img src="../rating/voting/pixel-vfl73.gif" alt=""> <span><?php echo $like?></span> </button> </form> </td> <td width="52%"> <form action="" method="post"> <input name="id" type="hidden" value="<? echo $page_id ?>" /> <input name="submitted" type="hidden" value="dislike" /> <button type="submit" class="dislike_button" name="dislike" id="dislike" > <img src="../rating/voting/pixel-vfl73.gif" alt=""> <span><? echo $dislike?></span> </button> </form> </td> </tr> </table> <? } ?> The problem is the vote does not add up or update the database, also it doesn't seem to be checking if the user has voted or not, it just attempts (but fails) to add a vote no matter what Thanks for any help. Hi Guys, I am designing this website that takes votes on images. I need to store the votes for each image against the image name and a username. For this purpose, I need to modify the current code which retrieves votes from the voting system but doesn't have a system to enter the image name dynamically. Below is the code for the same: Code: [Select] <?php ob_start(); $host="localhost"; $username="computat_abhi"; $password="[..]"; $databasename="computat_button"; $tbl_name="record"; $db=mysql_connect ("localhost", "computat_abhi", "[..]")or die(mysql_error()); mysql_select_db($databasename, $db) or die(mysql_error()); if( isset($_POST['Like']) ) { $sql = 'INSERT INTO record(ImageNumber,LikeCounter) VALUES (\'b1\', 1)'; mysql_query($sql, $db) or die(mysql_error()); echo 'Like vote is registered'; } elseif(isset($_POST['Dislike'])) { $sql = 'INSERT INTO record(ImageNumber,DislikeCounter) VALUES (\'b1\', 1)'; mysql_query($sql, $db) or die(mysql_error()); echo 'Dislike vote is registered'; } ob_end_flush(); ?> <html> <head> <title> Do you Like/Dislike this image? </title> </head> <body> <h1> Do you Like/Dislike this image? </h1> <form name="form1" method ="post"> <input type="submit" name="Like" value="Like"> <input type="submit" name="Dislike" value="dislike"> </form> </body> </html> Another issue is to register a new user on the website www.computationalphotography.in and link it with the voting system above. Looking forward to your help and suggestions. Hello everyone. I recently coded a Minecraft Voting for Diamonds script. Basically, you enter your username, you vote on the sites, then click "Get Reward". The reward then goes through a RCON script, and rewards the user with their diamonds in-game. the full script works fine, and I am happy with it, but there is one small problem; and that is users being able to abuse the system. If they wanted to, they could just refresh the page, and click Get Rewarded again, and again. I want to make something like this: It has a countdown on the link, which is started upon click, and then the link re-activates when the timer is done. My script already has "disabled=..." tags, so you have to click all links, this way would make sure a user cannot click the link until the timer is done. I'm pretty new to PHP, and please forgive me if it is not 100% PHP, but this place seemed extremely helpful. I am also pretty new to PHP, so make it for dummies xD Thanks everyone! Im displaying the results of a database by using a while loop... so Im trying to figure out how to delete some entries from the datbase. What I wanted to do is add a button in each result that will have the value "delete"... but I cant figure out how to do this. Im kinda new to mysql. I just want it so when I click the button the result will get deleted from the database. I did some research on this but I cant really grasp the examples. Can anybody help me out with this one? Thanks! Hi folks, I try to keep my explanation as short as possible. I have a page that loads a php script on opening with all the cards in my database. When a player clicks a div of a specific card div a popup comes up asking if he wants to add this card to his collection. When choosing yes the specific card goes into his private collection. Problem is, the card div has already got an ID for layout purpose. Can i give this div somekind of extra info while generating them from my PHP script. And then sent that info back to the PHP script that should add the card to the players DB. I am using Jquery to sent and receive data from my php script something like this. Code: [Select] <script> $(document).ready(function(){ $('#halfrow').click(function(){ //<-- the div that gets clicked $('#popuplarge').css({'visibilty':'visible'}) //<-- the popup $.post( "addcard.php", { cardID: $("#cardDiv").val()}, //<--- here i sent the info to the php script so the correct card can be added. function(data) { $("#popuplarge").html(data); }); }); }); </script> Is there a way to add a hidden <input /> with the card ID div and then sent that trough with Jquery? Still the same problem here as all the divs have the same ID and the jquery script would not know witch hidden <input /> to sent. I could also make the whole div a button but thats probably not desirable for layout purpose. I can always add a button to the div wich has to be clicked. But i would really like the user can click anywhere on the div. And i rather not want to redesign the div . I have a PHP application where I am trying to execute a PHP routine when the user clicks on a link to go to another page. The routine needs to execute before I use a header location command to send the user to the next location. I can't do this all with JavaScript, but it could be part of the solution if necessary. I'd prefer to just use PHP if I could, but I'm not sure that this is possible. Can anyone share with me a brief example of how I could do this? Thanks! Hi
I'm trying to change an image when a certain link is clicked. The image is a logo of a company and the links that will be clicked is english, arabic, and Chinese.
So if someone clicks on Chinese then the logo changes to the Chinese version of the normal logo.
Here is my html
<?php $langArabic=''; $langChinese=''; $langSpanish=''; $langEng=''; $linkArabic=getSEOLink($page_id); $linkChinese=getSEOLink($page_id); $linkSpanish=getSEOLink($page_id); $linkEng=getSEOLink($page_id); $queryLink = mysql_query("SELECT * FROM $_SEO_TABLE WHERE `id_page`='".$page_id."'"); if(mysql_num_rows($queryLink) > 0){ $resultLink = mysql_fetch_object($queryLink); if($resultLink->url != ''){ $linkEng = $_HTTP_ADDRESS."".$resultLink->url; if($page_id == 1 || $page_id == '1'){ $linkEng = $_HTTP_ADDRESS; } } if($resultLink->url_arabic != ''){ $linkArabic = $_HTTP_ADDRESS."".$resultLink->url_arabic; } if($resultLink->url_chinese != ''){ $linkChinese = $_HTTP_ADDRESS."".$resultLink->url_chinese; } if($resultLink->url_spanish != ''){ $linkSpanish = $_HTTP_ADDRESS."".$resultLink->url_spanish; } } switch (urlExtension()) { case 'html': $langClass = ''; $langEng='langActive'; $langTag='en'; break; case 'ar': if($page->title_arabic == ''){ $langClass = '_arabic'; }else{ $langClass = '_arabic'; } $langArabic='langActive'; $langTag='ar'; break; case 'es': $langClass = ''; $langSpanish='langActive'; $langTag='es'; break; case 'cn': $langClass = ''; $langChinese='langActive'; $langTag='cn'; break; default: $langClass = ''; $langEng='langActive'; $langTag='en'; } ?> <a class="main-logo<?php echo $langClass;?>" href="javascript:void(0);"><img src="<?php echo $_HTTP_ADDRESS;?>images/logo-letters.png" /></a> <div class="language-selection-wrapper<?php echo $langClass;?> overlay-bg<?php echo $langClass;?> border-bottom-white<?php echo $langClass;?> padding-level-one<?php echo $langClass;?>"> <div class="language-inner-wrapper<?php echo $langClass;?>"> <a class="<?php echo $langEng;?>" href="<?php echo $linkEng;?>">English</a><span>|</span> <a class="<?php echo $langArabic;?>" href="<?php echo $linkArabic;?>">العربيّة</a><span>|</span> <a class="<?php echo $langSpanish;?>" href="<?php echo $linkSpanish;?>">Español</a><span>|</span> <a class="<?php echo $langChinese;?>" href="<?php echo $linkChinese;?>">中文</a> <div class="clearboth"></div> </div> So, I just don't know where to post this question. I've written a quiz program where 50 English vocab words are pulled from a dB and displayed on one page with the order scrambled. My students then type the Spanish translation for each. When they submit the form the next page grades their work. They have to get a 90 or better for the grade to be automatically recorded, so I want them to click the back button and go back and make corrections. The problem is when they use a Chrome browser and click the back button the program re-sorts the order of questions. It leaves the order of their answers the same. So what they answered for number 1 is still in the field for number 1, but the questions (the English vocab word) is different. Chrome does this consistently so I thought this was a Chrome issue only. Then one of my students said the same thing happened to her when using Safari. So here is my question, how can I stop Chrome (or any other browser) from re-running my server-side PHP scripts (re-sorting the vocab array) when clicking the back button?
Here is the code for students taking the quiz:
<form method="post" action="portal.php?load=vquiz_grade" style="margin-left: 50px; line-height: 30px;">
$max = $count-1;
?>
//print "<br>";
<input type="hidden" name="max" value="<?print $max?>"> And here is the code showing them what they missed.
<?
// Total grade
print "You missed ".$wcount." words.<br>";
print "<table>";
// Grade response and set color
if ($wrong == 1){ if ($grade >= 90){
$query = "SELECT * FROM inno_vocab_assignments WHERE key_code = '$key_code' AND uname = '$secure_uname' AND teacher = '$teacher'";
// Prevent student from changing vocab list so as to do an easier list
// Insert grade
}
Thank you!
I have this code: echo "<td><a href = 'https://whatismyipaddress.com/ip-lookup' target = '_blank'>$col</a></td>"; the textbox I want to populate on the page has name attribute "LOOKUPADDRESS". it has no id attribute. after clicking on the link, is it possible to fill the textbox with $col? I am brand new to PHP but, after using W3 Schools, can retrieve a record from a MySQL database using php & SQLi.
I have a page with a list of between 20 and 30 items down one side and a panel on the other. When a user clicks a list item I want to display the details of the clicked item in the panel. The details a Program (text), Convenor (text), Dates (text), Times (Text), Location (text), Notes (Text large).
The details are stored in a MySQL Database 'Documents', in a table 'Programs' and I would like to put the details into text boxes in the panel.
Could you point me to some info on doing this please?
Thanks
|