PHP:警告:mysqli_stmt_bind_param():无效的对象或资源mysqli_stmt

时间:2018-05-29 17:32:52

标签: php html html5

我还在学习PHP的基础知识。但我需要为Uni制作一个项目,我需要在那里注册和登录页面。无论如何,当我试图创建我的user_register.php页面时,我得到了这个错误:

警告: mysqli_stmt_bind_param():第15行的C:\ xampp \ htdocs \ admin \ components \ user_register.php中的无效对象或资源mysqli_stmt

警告:mysqli_stmt_execute():第16行的C:\ xampp \ htdocs \ admin \ components \ user_register.php中的无效对象或资源mysqli_stmt

警告:mysqli_stmt_bind_result():第17行的C:\ xampp \ htdocs \ admin \ components \ user_register.php中的无效对象或资源mysqli_stmt

警告:mysqli_stmt_store_result():第18行的C:\ xampp \ htdocs \ admin \ components \ user_register.php中的无效对象或资源mysqli_stmt

警告:mysqli_stmt_num_rows():第20行的C:\ xampp \ htdocs \ admin \ components \ user_register.php中的无效对象或资源mysqli_stmt

CODE:

  <?php include_once "../connections/connection.php";

    $link = new_db_connection();
    $stmt = mysqli_stmt_init($link);
    $query = "SELECT nome_user,email FROM utilizadores WHERE nome_user LIKE ?";

    mysqli_stmt_prepare($stmt, $query);
    mysqli_stmt_bind_param($stmt, 's', $_POST['email']);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_bind_result($stmt,  $email_verifica);
    mysqli_stmt_store_result($stmt);

    if (mysqli_stmt_num_rows($stmt) == 0) {


        $query = "INSERT INTO utilizadores (nome_user, email, password) VALUES (?,?,?)";


        if (mysqli_stmt_prepare($stmt, $query)) {

            mysqli_stmt_bind_param($stmt, 'sss', $username, $email, $password_hash);

            $username = $_POST['username'];
            $email = $_POST['email'];
            $password_hash = password_hash($_POST['password'], PASSWORD_DEFAULT);

            // devemos validar também o resultado do execute!

            if (mysqli_stmt_execute($stmt) == true) {

                header("Location: ../login.php");


            } else {
                echo "Something's wrong";
            }

            mysqli_stmt_close($stmt);
            mysqli_close($link);

            // Acção de sucesso


        } else {

            mysqli_close($link);
            // Acção de erro
        }


    }

    else {

        echo "poop";
    }

HTML

<div class="row">
        <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
            <div class="login-panel panel panel-default">
                <div class="panel-heading">Login de Administração <span>Centro de Ciência Viva Aveiro</span></div>
                <div class="panel-body">
                    <form role="form" method="post">
                        <fieldset>
                            <div class="form-group">
                                <input class="form-control" placeholder="E-mail" name="email_login" type="email" autofocus="">
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="Password" name="password_login" type="password" value="">
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input name="remember" type="checkbox" value="Remember Me">Remember Me
                                </label>
                            </div>
                            <a href="index.html" class="btn btn-primary">Login</a></fieldset>
                    </form>
                </div>
            </div>
        </div><!-- /.col-->
    </div><!-- /.row -->

感谢!!!

0 个答案:

没有答案