PHP mysql邀请码注册表格


php mysql invitation code for registration form

如果有人能帮助我,我将再次感激不尽!我正在做一个注册表格,它工作得很好,但我想在那里实现一个邀请码检查。

我从来没有这样做过,因为我是一个新手,我只是寻找一个解决方案,试图理解和采用…所以请不要评判我:)我只是在努力学习每一步!

我要做的是->

  1. 用户输入邀请码2.如果不正确(在数据库中检查然后->错误消息)
  2. 如果正确(检查在数据库->然后得到使用)
  3. 代码数据库被更新,代码不再可用
下面是我的代码:
$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'];
}

不工作的是检查"已经使用",它在数据库中得到更新。工作得很好。错误必须是检查,但我不知道如何连接它与"如果(空($_POST['invite_code']))…": -/

提前感谢您的帮助!

,这部分工作!->

//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());
}

看起来您的查询格式不正确。你有:

SELECT `code` from tableinvitecodes WHERE '$invite_code' AND `taken` = '0'

我认为你应该这样写:

SELECT `code` from tableinvitecodes WHERE <<SOMETHING HERE>> = '$invite_code' AND `taken` = '0'