dtja73027 2019-02-10 18:50
浏览 90

为什么我的最后两个变量没有插入数据库?

For some reason my last two variables will not input into the database. I am referring to $verifyKey and $keyExpire. Here is my code with comments. I am adding the entire page to make sure I don't have the wrong character somewhere it isn't supposed to be. Effectively this is a registration page that inserts the information into the database and gives a verification key for email verification later.

I have the fields matched up with the code in the database and they are set to longtext and text. I don't want to insert directly as I am trying to get this method to work with all 5 variables.

<?php

// This is not seen by the end user so this file is placed in the unseen folder
// Check if the user used the sign up button


if (isset($_POST['signup-submit'])) {
    // uses the database handler
    require 'dbh.php';
    $username=$_POST['uid'];
    $email=$_POST['mail'];
    $password=$_POST['pwd'];
    $passwordcnfrm=$_POST['pwd-cnfrm'];
    $verifyKey=md5(time().$username);
    $keyExpire=date("U")+ 86400;


    // Checks to see if any field are empty
    if(empty($username)||empty($email)||empty($password)||empty($passwordcnfrm)) {

        // This header returns the username and/or email address so the user doesn't have to retype it
        header("Location:../signup.php?error=emptyfields&uid=".$username."&mail=".$email);

        exit();
    }
    // Checks if both the user and email are invalid
    else if (!filter_var($email, FILTER_VALIDATE_EMAIL)&&!preg_match("/^[a-zA-Z0-9]*$/",$username)) {
        header("Location:../signup.php?error=invalidmailuid");
        exit();
    }
    // Checks if the email is valid
    else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        header("Location:../signup.php?error=invalidmail&uid=".$username);
        exit();
    }
    // Checks if the username is valid.
    else if (!preg_match("/^[a-zA-Z0-9]*$/",$username)) {
        header("Location:../signup.php?error=invaliduid&mail=".$email);
        exit();
    }
    // Checks to see if the password and confirm password match
    else if ($password !== $passwordcnfrm){
        header("Location:../signup.php?error=passwordcheck&uid=".$username."&mail=".$email);
        exit();
    }
    // Checks to see if the username is already in use or password is invalid
    else {

        $sql = "SELECT uidUsers FROM users WHERE uidUsers=?";
        $stmt = mysqli_stmt_init($conn);
        if (!mysqli_stmt_prepare($stmt,$sql)) {
            header("Location:../signup.php?error=sqlerror");
            exit();
        }
        else {
                mysqli_stmt_bind_param($stmt,"s",$username);
                mysqli_stmt_execute($stmt);
                mysqli_stmt_store_result($stmt);
                $resultCheck = mysqli_stmt_num_rows();
                if ($resultCheck < 0){
                    header("Location:../signup.php?error=usertaken&mail=".$email);
                    exit();
                }
                else {
                    //Inserts into database

                    $sql = "INSERT INTO users (uidUsers,emailUsers,pwdUsers,verify,expires) VALUES (?,?,?,?,?);";
                    $stmt = mysqli_stmt_init($conn);

                    if (!mysqli_stmt_prepare($stmt,$sql)) {
                        header("Location:../signup.php?error=sqlerror");
                        exit();
                    }
                    else {
                        $hashedPwd =password_hash($password,PASSWORD_DEFAULT);

                        mysqli_stmt_bind_param($stmt,"sssss",$username,$email,$hashedPwd,$verifyKey,$keyExpire);
                        mysqli_stmt_execute($stmt);

                        header("Location:../signup.php?signup=success");

                    }

                }    
            }   
        }
    //Closes session to db
    mysqli_stmt_close($stmt);
    mysqli_close($conn);

}
else {
    header("Location:../signup.php");
}
  • 写回答

1条回答 默认 最新

  • dongyou8368 2019-02-10 19:18
    关注

    In description of mysqli_stmt::bind_param there is this criptic note:

    If data size of a variable exceeds max. allowed packet size (max_allowed_packet), you have to specify b in types and use mysqli_stmt_send_long_data() to send the data in packets.

    http://php.net/manual/en/mysqli-stmt.bind-param.php

    Practically it means that for every longtext (and blob) field you have to additionally call mysqli_stmt_send_long_data after mysqli_stmt_bind_param. Otherwise you have this strange behavious when everything works ok, but fields are not set.

    评论

报告相同问题?

悬赏问题

  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?