Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <p> To activate your licence key, please fill out the form below </p>
- <br />
- <form action="activate_key.php" method="POST">
- <input type="text" name="key" value="" />
- <br />
- <input type="submit" name="activate" value="Activate Key" />
- </form>
- <?php
- //include connection file which we will create later.
- include('connect.php');
- //define table variables
- $db_name = "wills95_licence_key_generator";
- $db_table = "licencekeys";
- //get variable
- $_POST['key'];
- //sanitize input
- $key = strip_tags($_POST['key']);
- //further sanitization
- $key = mysql_real_escape_string($key);
- //take key and query database to ensure it is a valid key
- $key_active_value='NO';
- $key_query = "SELECT * FROM "$db_name"."$db_table" WHERE keycode="$key" AND active="$key_active_value"";
- $run_query=mysql_query($key_query);
- //count number of rows to ensure it matches 1 and the key is valid
- $rows = mysql_num_rows($run_query);
- if($rows =="1"){
- // set key status to no longer active
- //activate key and set to activated status.
- $set_active_value='YES';
- $key_active_value='NO';
- $sql_update = "UPDATE `"$db_table"` SET active="$set_active_value" WHERE keycode= "$key" AND active="$key_active_value" ";
- $run_update = mysql_query($sql_update);
- if(!$run_update) {
- echo "There has been an error, please try again" ;
- } else {
- echo "Your key has successfully been activated, thank you for activating your key";
- }
- } else {
- echo "There was an error, your key has not been activated, please try again";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment