mysql 邀请码,php mysql邀请码注册表格

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'

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值