我对php和mysql很陌生。我在索引中添加了一个注册字段“referror”。我添加它最简单的方法就是在player表中添加ref行。当用户在注册期间输入一个引用时,它会被存储到数据库中,而不检查新用户输入的用户名是否有效。
if (isset($_POST['register'])) {
$username = $_POST['username'];
$password = hash('sha256', $_POST['password']);
$email = $_POST['email'];
$ref = $_POST['ref'];
$sql = mysqli_query($connect, "SELECT username FROM `players` WHERE username='$username'");
if (mysqli_num_rows($sql) > 0) {
echo '<br /><div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' . lang_key("username_taken") . '</div>';
} else {
$sql2 = mysqli_query($connect, "SELECT email FROM `players` WHERE email='$email'");
if (mysqli_num_rows($sql2) > 0) {
echo '<br /><div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' . lang_key("email_taken") . '</div>';
} else {
$money = $row['startmoney'];
$gold = $row['startgold'];
$themeid = $rowtd['id'];
$langcode = $rowld['langcode'];
$insert = mysqli_query($connect, "INSERT INTO `players` (username, password, email, ref, money, gold, theme, language) VALUES ('$username', '$password', '$email', '$ref', '$money', '$gold', '$themeid', '$langcode')");
今天,我希望在推荐人时给予奖励。所以我一直在分解我要做的事情。我想出了这样的办法。
$sql3 = mysqli_query($connect, "SELECT ref FROM `players` WHERE ref='$ref'");
if (mysqli_num_rows($sql3) > 0) {
echo $player_update = mysqli_query($connect, "UPDATE `players` SET money=money+'5000' WHERE ref='$ref'");';
}else{
这不起作用,我不确定这是否是我应该做的第一位。。我是一个初学者,自学成才,所以小费将非常感谢,谢谢大家阅读/帮助!
暂无答案!
目前还没有任何答案,快来回答吧!