I would really appreciate once again if someone could help me out! I'm working on a registration form which works fine, but I wanted to implement an invitation code check in there, too.
I never did that before and since I'm a newbie I just searched for a solution, tried to understand and to adopt...so please don't judge me :) I'm just trying to learn with each step!
So quick what I'm trying to do ->
user types in an invitation code
2.if incorrect (checked in the database then -> error msg)
if correct (checked in database -> then gets used)
code database gets updated that the code is not usable anymore
here is my code:
$invite_code = ($_POST['invite_code']);
// Validate invite code
if (empty($_POST['invite_code'])) {
$err7 = "Wrong invitation code";
}
//check if invitation code is valid in the database and not already taken
$rs_check = mysql_query("SELECT `code` from tableinvitecodes WHERE '$invite_code'
AND `taken` = '0'") or die (mysql_error());
$num = mysql_num_rows($rs_check);
// Match row found with more than 0 results - the code is invalid.
if ( $num <= 0) {
$err7 = "Invite code is invalid";
}
else {
$invite_code = $_POST['invite_code'];
}
what's not workin is the check for the "being used already", it gets updated in the database..that's working fine. The mistake must be the checking but I don't know how to connect it with the "if (empty($_POST['invite_code']))..." :-/
Thanks in advance for your help!
and that part works! ->
//set approved code to 1 to block that code
if(empty($err7)) {
$rs_invite_code = mysql_query("update tableinvitecodes set `taken` = '1' WHERE
code='$invite_code' ") or die(mysql_error());
}
解决方案
It looks like your query is mal-formed. You have:
SELECT `code` from tableinvitecodes WHERE '$invite_code' AND `taken` = '0'
I think you should have something like:
SELECT `code` from tableinvitecodes WHERE <> = '$invite_code' AND `taken` = '0'