This topic is locked

Need help with custom registration question

2/20/2014 9:35:45 PM
PHPRunner General questions
K
karmacomposer author

I added a field to the stock registration form with a serial number field. I have a table pre-filled with existing serial numbers.
I need to look up the user's serial number they provide on the registration form and see if it already exists in the serial table.
What I want to do is see if their serial number is listed in the serial key table. If it is, then they can proceed with registering. If

it is not in the serial key table, then I want to stop the registration and send them to a web page where they can purchase a serial key.
I have the code that does this, but it seems I cannot place it in the 'before registration' event. If I do, I get a php error when I

attempt to login.
Where do I put this code fragment so it will work?
Here is the fragment (pretty standard and right out of the 'if record exists' option):

//********** Check if specific record exists ************
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;

}


First, is this even the right code to do what I am asking? I need to take what the user types in the field 'steamkey' and then compare it to all the keys in the table

called 'table_keys'. If the key is in there, proceed with registering. If it is not found, then they obviously did not buy a key and need to do so.
If the code above does NOT do this (my php coding is sooooooo bad), could anyone help me so that it DOES do what I need or at least point me in the correct

direction.
Thanks for anyone's help.
Mike

Sergey Kornilov admin 2/21/2014

Start by printing your SQL query on the screen and then execute it manually using phpMyAdmin. This can point you in the right direction.
More info:

http://xlinesoft.com/phprunner/docs/debugging_tips.htm

K
karmacomposer author 2/22/2014

I have exhaustedly looked for a solution and went to the sql section of phprunner and got the (what I believe to be) correct query and then I looked for how to compare a form fields with a existing database field (array) and

this is what I came up with:

// Place event code here.

// Use "Add Action" button to add code snippets.
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;

}


While it does not give me any errors, it does not work either. I have placed this in the BEFORE REGISTRATION event page.

Is there a more appropriate place to perform this lookup? If so, please let me know which event page I should be using.
I need to compare the registration form field 'steamkey' (the user's paid serial number) with an existing database of keys,

where the field is also called 'steamkey' (to make sure they paid for it)
What am I doing wrong?
Just a bit of help would mean all the difference and I only have a few more days to make this work for a friend of mine.
Mike

K
karmacomposer author 2/22/2014

This seems to work better and allows for a successful registration, but still does not work if a wrong key is entered - it succeeds anyway.

// Place event code here.

// Use "Add Action" button to add code snippets.
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;

}


What can I do to make it work?
Mike