运行注册表单时出现SQLSRV错误

时间:2018-07-18 14:30:53

标签: php sql sql-server azure sqlsrv

我正在使用php / sql处理我的用户注册/登录表单,最近我这次又从头开始重新制作,但工作方式有所不同(最好是,我希望:-))我正在尝试使用函数,但是使用第一个功能时我已经出现错误。这是我的代码:

    <?php
/**
 * Created by PhpStorm.
 * User: Thomas Adema
 * Date: 15-7-2018
 * Time: 22:06
 */

include_once("config.php");

$username = $_POST['username'];
$password = $_POST['password'];
$conpassword = $_POST['conpassword'];

$errors = array();

if ($password !== $conpassword) {
    $errors[] = "Passwords don't match";
}

if (count($errors) == 0) {
    $addUserStatus = addUser($conn, $username, $password);
    if ($addUserStatus === -1) {
        $errors[] = "Interne server error";
    }
}

if (count($errors) === 0 && addUserStatus === 1) {
    // user was addded
    $_SESSION['errMsg'] = "Registratie Succesvol!";
    header("location: ../index.php");
    exit();
} else {
    // do something with all the errors
    $_SESSION['errMsg'] = $errors;
    header("location: ../register.php");
    exit();
}


function addUser($conn, $username, $password) {
    $npassword = password_hash("$password", PASSWORD_DEFAULT);

    $sql = "INSERT INTO Gebruikers(username, password) VALUES (?, ?)";
    $params = array($username, $npassword);

    $stmt = sqlsrv_query( $conn, $sql, $params);
    if( $stmt === false ) {
        die( print_r( sqlsrv_errors(), true));
        return -1;
    }else{
        return 1;
    }

}

?>

现在还没有完成,但是当我运行它时,出现以下错误:

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -14 [code] => -14 [2] => An invalid parameter was passed to sqlsrv_query. [message] => An invalid parameter was passed to sqlsrv_query. ) )

任何人都可以帮助我,因为我无法弄清楚,这真令人沮丧。 提前致谢! 此致,托马斯·阿德玛(Thomas Adema)

0 个答案:

没有答案