0

如果有人可以帮助我,我将再次感激不尽!我正在制作一个可以正常工作的注册表单,但我也想在那里实现邀请码检查。

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

这么快我想做的事->

  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'];
}

不工作的是检查“正在使用”,它会在数据库中更新......这很好。错误一定是检查,但我不知道如何将它与“if (empty($_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());
}
4

1 回答 1

1

看起来您的查询格式错误。你有:

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

我认为你应该有类似的东西:

SELECT `code` from tableinvitecodes WHERE <<SOMETHING HERE>> = '$invite_code' AND `taken` = '0'
于 2012-12-30T00:45:36.950 回答