当用户通过推荐链接注册时,为什么用户数据没有插入引用表?

时间:2017-03-21 09:19:05

标签: php mysql login registration referrals

我正在尝试构建一个登录/注册系统,其中所有注册用户都有一个唯一的引荐链接,用于引用新用户。我还创建了一个表来跟踪特定用户引用系统的用户总数。 一切正常,但问题是,即使访问者通过推荐链接注册,推荐表也永远不会更新

代码:

if(isset($ref)){
    echo $ref;
    //implement the code here
    $send_user_id = $this->db_connection->prepare('SELECT user_id FROM users WHERE user_name = :user_name');
    $send_user_id->bindValue(':user_name',$ref,PDO::PARAM_STR);
    $send_user_id->execute();
    if($send_user_id->rowCount()){
        $send_user_id->fetchobject();
        $rsid = $send_user_id->user_id;
        //insert into referral
        $referral = $this->db_connection->prepare('INSERT INTO referrals (sending_user_id,new_user_id,new_user_status) VALUES (:sending_user_id, :new_user_id, 0)');
        $referral->bindValue(':sending_user_id',$rsid,PDO::PARAM_INT);
        $referral->bindValue('new_user_id',$user_id,PDO::PARAM_INT);
        $referral->execute();
    }else{
        $this->errors[] = "invalid referral id";
    }
    $this->registration_successful = true;
}

CONSTRUCTOR:

if(isset($_GET['ref'])){
    $ref = trim($_GET['ref']);
    if(isset($ref)){
        echo $ref;
    }else{
        echo "ref was not define";
    }
} else {
    $ref = false;
}
// if we have such a POST request, call the registerNewUser() method
if (isset($_POST["btn-save"])) {
    echo $ref;
    $this->registerNewUser($_POST['user_name'], $_POST['user_email'], $_POST['user_password_new'], $_POST['user_password_repeat'], $_POST["captcha"], $ref);

谢谢!

0 个答案:

没有答案