Remove key PHP? HOW?

Discussion in 'PHP' started by Kevstyle, Jan 5, 2013.

  1. #1
    I have a serial key php script, and i edited so it would delete the key but what am i doing wrong?

    <?php
        /* Grab the URL variable */    $key = $_GET["key"];
        /* Connect to database and grab the keys */    mysql_connect("localhost","keys","sql123")    or die("Couldnt connect to database server");    mysql_selectdb("keys")    or die("Couldnt select database");    $query = "SELECT `key` FROM `keys`";    $result = mysql_query($query);    $num=mysql_numrows($result);
        /* Set up a loop to check if requested key is found in database */    $i=0;    while ($i < $num) {
            $validationkey = mysql_result($result,$i,"key");
                if ($validationkey == $key) {                $validation = "Success";            }
            $i++;    }
        /* If a match was found in database, echo "VALID". Else echo "ERROR" */    if($validation != "") {              $query = 'DELETE FROM `keys` WHERE key=' . $key;        mysql_query($query);        echo 'Key $key activated and deleted to prevent scamming <br><input value="valid">'    } else {        header('Location: http://freemoneypot.com/showthread.php?tid=95');    }
    
    ?>
    PHP:
    Everything is fine exept this:
    
    /* If a match was found in database, echo "VALID". Else echo "ERROR" */    if($validation != "") {              $query = 'DELETE FROM `keys` WHERE key=' . $key;        mysql_query($query);        echo 'Key $key activated and deleted to prevent scamming <br><input value="valid">'    } else {        header('Location: http://freemoneypot.com/showthread.php?tid=95');    }
    
    PHP:
    Pastebin: http://pastebin.com/CdgD1yEQ
     
    Last edited: Jan 5, 2013
    Kevstyle, Jan 5, 2013 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    If the $key isn't found, $validation is undefined, so reading it [if($validation...) reads it] throws an error.
     
    Rukbat, Jan 5, 2013 IP