php mysql邀请码注册表格 [英] php mysql invitation code for registration form
问题描述
如果有人可以帮助我,我将非常感谢!我正在使用可以正常运行的注册表格,但是我也想在其中实施邀请代码检查.
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 ->
- 用户输入邀请码 2.如果不正确(在数据库中检入,则->错误消息)
- 如果正确(在数据库中检入->然后使用)
- 代码数据库已更新为该代码不再可用
- 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
这是我的代码:
$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']))..."连接起来:-/
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']))..." :-/
提前感谢您的帮助!
那部分起作用了! ->
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 <<SOMETHING HERE>> = '$invite_code' AND `taken` = '0'
这篇关于php mysql邀请码注册表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!