I want to make a log in page using mysqli and i get this error “Cannot pass parameter 1 by reference”

旧街凉风 提交于 2020-05-18 04:34:05

问题


And this is my code:

$q = "SELECT * FROM `my___passloging` WHERE `puser` = ? AND `ppass` = ?";       
$procces = $this->db->prepare($q); 
$procces->bind_result("ss", $user, $pass);

回答1:


You never executed your query.

$procces = $this->db->prepare($q); 

$procces->execute(); // this part

$procces->bind_result("ss", $user, $pass);

Example from the manual:

/* prepare statement */
if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
    $stmt->execute();

    /* bind variables to prepared statement */
    $stmt->bind_result($col1, $col2);
  • Unless you want to bind_param() instead of using bind_result(), to which you still need to execute that statement.

Example from the manual:

/* create a prepared statement */
if ($stmt = $mysqli->prepare("SELECT District FROM City WHERE Name=?")) {

    /* bind parameters for markers */
    $stmt->bind_param("s", $city);

    /* execute query */
    $stmt->execute();

    /* bind result variables */
    $stmt->bind_result($district);

References:

  • http://php.net/manual/en/mysqli-stmt.bind-result.php
  • http://php.net/manual/en/mysqli.prepare.php

Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Error reporting should only be done in staging, and never production.



来源:https://stackoverflow.com/questions/30867385/i-want-to-make-a-log-in-page-using-mysqli-and-i-get-this-error-cannot-pass-para

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!