我正在使用注册表中的注册密钥来工作一个网站,以便拥有它的用户可以使用我生成的reg密钥在我的网站中注册。
这就是我想要的
这是我的代码:
register.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$DB_HOST = "localhost"; // replace
$DB_NAME = "users"; // replace
$DB_USER = "root"; // replace
$DB_PASS = ""; // replace
$conn = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if($conn->connect_errno > 0) {
die('Connection failed [' . $conn->connect_error . ']');
}
if(isset($_POST['Register'])){
$inviteCode = ($_POST['inviteCode']);
if (empty($_POST['inviteCode'])) {
$err = "Wrong Invitation Code";
header ('Location: http://localhost/error');
}
$rs_check = mysqli_query($conn, "SELECT `inviteCode` from referrals WHERE '$inviteCode' AND `taken` = '0'");
$num = mysqli_num_rows($rs_check);
if ( $num <= 0) {
$err7 = "Invite code is invalid";
}
else {
$invite_code = $_POST['inviteCode'];
}
if(empty($err7)) {
$rs_invite_code = mysqli_query($conn, "update referrals set `taken` = '1' WHERE
inviteCode='$inviteCode' ");
}
}
?>
index.php
<form action="register.php" method="POST">
<div class="form-email">
<input type="text" placeholder="Invite Code" name="inviteCode" required/>
</div>
<div class="submit3">
<input type="submit" value="Invite" name="Register" />
</div>
</form>
注意:我的数据库名称是USERS,表是REFERRALS,我有3列EMAIL,INVITE CODE和TAKEN
答案 0 :(得分:0)
在查询的WHERE子句中,您需要指定要检查的字段。在这一行:
$rs_check = mysqli_query($conn, "SELECT `inviteCode` from referrals WHERE '$inviteCode' AND `taken` = '0'");
您应该写:
... WHERE "INVITE CODE"='$inviteCode' AND `taken` = '0'");
其中“邀请代码”是您在数据库中字段的名称