非匹配参数Mysqli / php

时间:2017-07-27 11:51:34

标签: php mysqli

我收到错误

  

警告:mysqli_stmt_bind_param():变量数不匹配   准备语句中的参数数量   第17行的C:\ wamp64 \ www \ testing \ view.php

任何人都可以看到我做错了,因为我可以看到它匹配

<?php
$connect = mysqli_connect("localhost", "user", "pass", "db");

if(mysqli_connect_error()){
    echo mysqli_connect_error();
    exit();

}

$query = "SELECT id, username, password FROM users";

$stmt = mysqli_prepare($connect, $query);

if($stmt){
    mysqli_stmt_bind_param($stmt,"iss",$id, $username, $password);
    mysqli_stmt_bind_result($stmt,$id, $username, $password);
    mysqli_stmt_execute($stmt);

    mysqli_stmt_fetch($stmt);   
    echo "ID: ".$id. "Username: ".$username."Password: ".$password;


    }
?>

1 个答案:

答案 0 :(得分:0)

我抬起头来,进一步阅读准备好的陈述,从头开始,但注册表格与登录表格相符。请告知这是否是正确发布此信息的正确方式,因为它似乎正在起作用。另外有没有办法在发布之前检查电子邮件是否重复?因为我试图这样做并获得命令不同步错误。我无法弄清楚如何绕过这个。如果有人能指出我正确的方向,那将非常感激。

<?php
require ("connect.php");
if(isset($_POST['reg'])) {
	
   
    $username = $_POST['username'];
	$password = $_POST['password'];
    $email = $_POST['email'];
    $about = $_POST['about'];
    $type = $_POST['type'];	
    $password_hash = password_hash($password, PASSWORD_DEFAULT);    
  

	if (empty($username)) {
		$msg = "Please create your username";
	} elseif (empty($password)) {
		$msg = "Please create your password";
	} elseif (empty($email)) {
		$msg = "Please enter your email";	
	} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
		$msg = "Invalid email format";		

	} else {
	
    if(!($stmt = $connect->prepare("INSERT INTO users (username, password, email, about, type) 
        VALUES (?,?,?,?,?)"))){
        echo "Failed: (" . $connect->errno . ")" . $connect->error;
    }

    if(!$stmt->bind_param('sssss', $username, $password_hash, $email, $about, $type)){
     echo "Failed:(" . $stmt->errno . ")" . $stmt->error;
    }

    if(!$stmt->execute()){
     echo "Failed: (" . $stmt->errno .")" . $stmt->error;
    }

    if($stmt) {
		echo "Registration Success!!";

    }
    else{
        echo "Registration failed";
    }
	}

	}
$connect->close();
?>