Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Could you check to see if my code is correct? Thanks.

    I have a code fragment that looks at a registration form and compares a field (steamkey) to a table with serial numbers (field name steamkey) to see if the steamkey is found in the table.
    If it is, then the registration form completes. If not, then it fails and the user is sent to purchase a key.

    Here is the code fragment that works on the registration page:

    Code:
    global $conn;
    $strSQLExists = "select * from table_keys where steamkey='" . $values["steamkey"] . "'";
    $rsExists = db_query($strSQLExists,$conn);
    $data=db_fetch_array($rsExists);
    if($data)
    {
    // if record exists do something
    $message = "Steam Key " . $values["steamkey"] . " already exists."
    return true;
    }
    else
    {
    // if dont exist do something else
    return false;
    }
    Return True = success and the registration completes
    Return False = fail

    I checked the query with PhpMyAdmin and it works 100%, so I need to know why this is not working. Is it my syntax?

    I would appreciate anyone's input.

    Thank you.

    Mike

  • #2
    New Coder
    Join Date
    Oct 2010
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That was the wrong version of the code fragment. Here is the correct one:

    Code:
    global $conn;
    $strSQLExists = "SELECT steamkey FROM table_keys";
    $rsExists = db_query($strSQLExists,$conn);
    $data=db_fetch_array($rsExists);
    
    if ($_POST['steamkey']==$data)
    {
    //successful comparison
    return true;
    }
    else
    {
    //unsuccessful comparison
    return false;
    }
    Please note that this is a code in a php creation software, so this chunk simply does something - in this case, after the user fills out a form, and before it is saved to the database, it executes this code which checks to see if the key that was entered is valid and found in the table_keys table.

    Thanks for a speedy reply.

    Mike

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Posts
    462
    Thanks
    0
    Thanked 20 Times in 20 Posts
    if (isset($_POST['steamkey']) && !empty($_POST['steamkey'])){
    $input_key = $_POST['steamkey'];

    //--- begin key check ---//
    global $conn;
    $strSQLExists = "select * from table_keys where steamkey = $input_key ";
    $rsExists = db_query($strSQLExists,$conn);
    $data = mysql_num_rows($rsExists);

    if(!$data){
    //--- process key ---//\
    }
    else{
    //--- key does not exist return to form ---//
    }
    }//[end isset$_POST[]]
    NO Limits!! DHCreationStation.com
    ------------------------------------------------------------
    For projects using MediaTypes (MIMETypes) visit E-BAM.net -(updated weekly)

    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #4
    New Coder
    Join Date
    Oct 2010
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you. It's not working, but I do not think it's your code. The software I use is very difficult to work with and if I could figure out a better, faster way to do what I need I would do it.

    One question though. Isn't there supposed to be something like

    if $data == $input_key {
    Do something}
    Else {
    Do something different}

    Or something like that. As it is written now, how is the table data array being compared to the form field?

    Thanks again so much for your help.

    Mike
    Last edited by MikeFelker; 02-23-2014 at 06:13 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •