Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. //DB-varaibles
  4. $host = "dbirkemalm.com.mysql";
  5. $username = "dbirkemalm_com";
  6. $password ="8ejxQ4Pn";
  7. $db_name = "dbirkemalm_com";
  8. $ip_table = 'ips';
  9. $vote_table = 'votes';
  10.  
  11. //Variables
  12. $ip = $_SERVER['REMOTE_ADDR'];
  13. $vote = $_GET['id'];
  14.  
  15. //Connect to DB
  16. mysql_connect("$host", "$username", "$password") or die ("Could not connect");
  17. mysql_select_db("$db_name") or die ("Cannot select DB");
  18.  
  19. //Check if IP exists in DB.
  20. $checkip = ("SELECT * FROM $ip_table WHERE ip = '$ip'") or die(mysql_error());
  21. $checkipr = mysql_query($checkip) or die(mysql_error());
  22. $iprows = mysql_num_rows($checkipr);
  23.  
  24.  
  25. //If IP does not exist, insert it.
  26. if($iprows == 0){
  27.     $ipinsert = ("INSERT INTO $ip_table VALUES($ip)") or die(mysql_error());
  28.     $ipinsquery = mysql_query($ipinsert) or die(mysql_error());
  29.     //When IP is inserted, do vote.
  30.     $votequery = ("INSERT INTO $vote_table VALUES('$vote')") or die (mysql_error());
  31.     mysql_real_escape_string($vote);
  32.     $dovote = mysql_query($votequery) or die(mysql_error());
  33. }
  34.  
  35. else{
  36.     echo "Nothing";
  37. }
  38.  
  39.  
  40.  
  41.  
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement