Author Topic: [ PHP + MySQL ] Star voting  (Read 4430 times)

0 Members and 1 Guest are viewing this topic.

Matrix

  • Guest
[ PHP + MySQL ] Star voting
« on: November 01, 2011, 05:22:57 pm »
yourfile.php
Code: [Select]
<?php
/********** Connection to base *************/
$conn mysql_connect('localhost','root','') or die("Fatalna greška: Ne mogu da se konektujem s' ovim podacima!");
mysql_select_db('test'$conn) or die("Fatalna greška: Uneta baza ne postoji!");
/********** End of Connection to base ************/


/********** Showing votes *************/
echo "1 zvezdicu je daolo <b>".mysql_num_rows(mysql_query("SELECT vote FROM vote WHERE vote=1"))."</b> ljudi.<br>
2 zvezdice je daolo <b>"
.mysql_num_rows(mysql_query("SELECT vote FROM vote WHERE vote=2"))."</b> ljudi.<br>
3 zvezdice je daolo <b>"
.mysql_num_rows(mysql_query("SELECT vote FROM vote WHERE vote=3"))."</b> ljudi.<br>
4 zvezdice je daolo <b>"
.mysql_num_rows(mysql_query("SELECT vote FROM vote WHERE vote=4"))."</b> ljudi.<br>
5 zvezdica je daolo <b>"
.mysql_num_rows(mysql_query("SELECT vote FROM vote WHERE vote=5"))."</b> ljudi.";
/********** Kraj prikaza trenutnog broja glaova **********/


$fajl $_SERVER['PHP_SELF'];
$slika "<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP gvaeTAAAAB3RJ
TUUH2QcRFDg6adxlSAAAAa9JREFUOI3F089KG1EUx/HPTVJNRrvsExRbaQVFiPgApSuXcdvuhQas
ZCElq9KVWKEg0mXfwZX0GYoIChb6AK5LMxM1uV04xqaOTcBFLxzO5fCb7z3/hv9xYstibFkcR1sZ
i1jTyG/fRklLYwETDckAej9g3LFgyowpM3HHwr2BpjUkSPL7vYGJ1QEwsTpKHuIbj0x5qIpJhnzV
Y1UHyrm6h8xLmR8ydBnyv/ysKKvgs5IXKngwgFHL/fUuXCI4GKTTz2MX4KuyVwEiwXtvJT6omZTk
sGtfywFpbp0h39XxTtvHQCxBIIa2bSXLOBnZ15tzomQ5tG0HIn8NJaw7VFbXt6cnDsrp5HaRl9gT
9e0pq4d1h0OMu56OX5ya9MQEQ0M5R9f38NrTou8KgfGTZ6qOTbga0nUd/TzLc2Seh bt9hTv4YVV
mZvGd3Rzu4pluabgFANTjcFEU8e6lnQtSR3/ES/8a24B46ZZmTmZKLXrUj2sOQprjlyqS 3KRJm5
uGm2MKEhYFM7bjiLLSt3alpW4oaz2NQep RpqfmwZf8uYNiyLzWP6dEZ/mOVxtH BihsjmJuUA p
AAAAAElFTkSuQmCC
'>"
;


/**** What to vote *****/
echo "<br><br>
<a href='"
.$fajl."?vote=1'>".$slika." Dodaj 1 zvezdicu</a><br>
<a href='"
.$fajl."?vote=2'>".$slika." Dodaj 2 zvezdice</a><br>
<a href='"
.$fajl."?vote=3'>".$slika." Dodaj 3 zvezdice</a><br>
<a href='"
.$fajl."?vote=4'>".$slika." Dodaj 4 zvezdice</a><br>
<a href='"
.$fajl."?vote=5'>".$slika." Dodaj 5 zvezdica</a>";
/**** End of what to vote *****/






if (isset($_GET['vote']))
{
/****** Protect from SQLi ********/
if(isset($_GET['vote']) && is_numeric($_GET['vote']))
   {
      
$vote $_GET['vote'];
   }
elseif(!
is_numeric($_GET['vote']))
   {
      die(
"Pokusaj hakerskog napada."); 
   }
/***** End of Protect from SQLi****/
   
/*** If vote is smaller than 1 or bigger than 5 show error ***/
if($vote<1||$vote>5) {
   die(
"<br><b>Ne mozete dati manje od 1 zvezdice ili vise od 5 zvezdica!</b>");
}
/*** Because is onli 5 stars ***/


$ip $_SERVER['REMOTE_ADDR'];


/******** AIf you are allready vote this will disable vote for you *****/
if(mysql_num_rows(mysql_query("SELECT * FROM vote WHERE ip='".$ip."'")) == 1) {
      die(
"<script language='javascript'>javascript:alert('Vec si glasao.');</script>");
   }
/****** End *****/
   
/*** Insert number of stars and ip addres of voter ***/
mysql_query("INSERT INTO vote(ip,vote) values('".$ip."','".$vote."')") or die(mysql_error());
   echo 
"<script language='javascript'>javascript:alert('Uspesno ste glasali!');</script>
   <script language='javascript'>location.replace('"
.$fajl."')</script>";
/*** End Insert ****/
}
?>


Enjoy. :)
« Last Edit: November 01, 2011, 07:22:16 pm by Matrix »

Online ande

  • Owner
  • King
  • *
  • Posts: 2460
  • Cookies: 222
    • View Profile
Re: [ PHP + MySQL ] Star voting
« Reply #1 on: November 01, 2011, 06:18:26 pm »
Care to translate those comments? :P Makes no sense to me.

Matrix

  • Guest
Re: [ PHP + MySQL ] Star voting
« Reply #2 on: November 01, 2011, 07:22:29 pm »
Done.

Online ande

  • Owner
  • King
  • *
  • Posts: 2460
  • Cookies: 222
    • View Profile
Re: [ PHP + MySQL ] Star voting
« Reply #3 on: November 01, 2011, 08:49:41 pm »
Done.

Great ;) Now it makes a bit more sense :P

Offline bluephantom

  • Serf
  • *
  • Posts: 23
  • Cookies: 0
  • Gender: Male
  • Malanghackerlink
    • View Profile
    • My Profile
Re: [ PHP + MySQL ] Star voting
« Reply #4 on: December 12, 2011, 05:41:05 pm »
Nice Post  :o
“Maybe there are no right moments, right guys, right answers, maybe sometimes you just to say what’s in your heart”

 



Intern0t SoldierX SecurityOverride programisiai
Want to be here? Contact Ande, Bluechill or Kulverstukas on the forum or at IRC.