Home > Enterprise >  FOUND ERROR: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not d
FOUND ERROR: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not d

Time:11-15

Hello everyone I got some error in my code, something like this

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in D:\Coding\Xampp\htdocs\kurirku\php\control\sign_up.php on line 25

and I've tried to fix this but I can't find the resolve that error, maybe someone can help? this is the full code

require_once ("../connection/connect.php");

if(isset($_POST['register'])){
    $f_name = filter_input (INPUT_POST, 'f_name', FILTER_SANITIZE_STRING);
    $l_name = filter_input(INPUT_POST, 'l_name', FILTER_SANITIZE_STRING);
    $mail = filter_input(INPUT_POST, 'mail', FILTER_VALIDATE_EMAIL);
    $pass = password_hash($_POST["pass"], PASSWORD_DEFAULT);


    //menyiapkan querry
    $sql = "INSERT INTO tb_daftar (f_name, l_name, email, pass)
            VALUES (:f_name, :l_name, :mail, :pass)";
    $stmt = $db->prepare($sql);

    $params = array(
        ":f_name" != $f_name,
        ":l_name" != $l_name,
        ":email" != $mail,
        ":pass" != $pass
    );

    //eksekusi untuk menyimpan ke database
    //THIS IS LINE 25
    $saved = $stmt->execute($params);

    if($saved) header("Location: ../view/data.php");
}

CodePudding user response:

$params, right now, is a list with 4 boolean, [true, true true, true]. To create an associative array,

    $params = array(
        ":f_name" => $f_name,
        ":l_name" => $l_name,
        ":email" => $mail,
        ":pass" => $pass
    );
  • Related