Guest User

PHP script

a guest
Aug 18th, 2013
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. <html>
  2. <p> To activate your licence key, please fill out the form below </p>
  3. <br />
  4. <form action="activate_key.php" method="POST">
  5. <input type="text" name="key" value="" />
  6. <br />
  7. <input type="submit" name="activate" value="Activate Key" />
  8. </form>
  9.  
  10. <?php
  11.  
  12. //include connection file which we will create later.
  13. include('connect.php');
  14.  
  15. //define table variables
  16.  
  17. $db_name = "wills95_licence_key_generator";
  18. $db_table = "licencekeys";
  19.  
  20. //get variable
  21.  
  22. $_POST['key'];
  23.  
  24. //sanitize input
  25.  
  26. $key = strip_tags($_POST['key']);
  27.  
  28. //further sanitization
  29.  
  30. $key = mysql_real_escape_string($key);
  31.  
  32. //take key and query database to ensure it is a valid key
  33.  
  34. $key_active_value='NO';
  35. $key_query = "SELECT * FROM "$db_name"."$db_table" WHERE keycode="$key" AND active="$key_active_value"";
  36. $run_query=mysql_query($key_query);
  37.  
  38.  
  39. //count number of rows to ensure it matches 1 and the key is valid
  40.  
  41. $rows = mysql_num_rows($run_query);
  42.  
  43. if($rows =="1"){
  44.  
  45. // set key status to no longer active
  46.  
  47. //activate key and set to activated status.
  48.  
  49. $set_active_value='YES';
  50. $key_active_value='NO';
  51. $sql_update = "UPDATE `"$db_table"` SET active="$set_active_value" WHERE keycode= "$key" AND active="$key_active_value" ";
  52. $run_update = mysql_query($sql_update);
  53.  
  54. if(!$run_update) {
  55.  
  56.  
  57. echo "There has been an error, please try again" ;
  58.  
  59. } else {
  60.  
  61. echo "Your key has successfully been activated, thank you for activating your key";
  62.  
  63. }
  64.  
  65.  
  66. } else {
  67.  
  68. echo "There was an error, your key has not been activated, please try again";
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment