简体   繁体   English

php 错误:致命错误:未捕获 PDOException:SQLSTATE[HY093]:无效参数号:绑定变量数与令牌数不匹配

[英]php error : Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

I am new to PHP and i have got this error:我是 PHP 的新手,我遇到了这个错误:

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens致命错误:未捕获的 PDOException:SQLSTATE[HY093]:无效的参数号:绑定变量的数量与标记的数量不匹配

I don't know what is it and how to solve, I searched over the internet but I couldn't find nothing.我不知道它是什么以及如何解决,我在互联网上搜索但我什么也找不到。

My PHP code:我的 PHP 代码:

<?php

  #DB connect
  $bdd = new PDO('mysql:host=localhost;dbname=alfarabi_website','root','');

  #Requete
  $requete = $bdd -> prepare('INSERT INTO users (prenom,nom,anniversaire,genre,email,password,role) VALUES(?,?,?,?,?,?,?)');
  $requete -> execute(array(isset($_POST['first_name'] ,$_POST['last_name'],$_POST['birthday'],$_POST['gender'],$_POST['email'],$_POST['password'],$_POST['subject'])));

?>

You have to do isset before,你必须先做isset,

$first_name = isset($_POST['first_name'] ? $_POST['first_name']  : null ;
$last_name= isset($_POST['last_name'] ? $_POST['last_name']  : null ;
$birthday= isset($_POST['birthday'] ? $_POST['birthday']  : null ;

Then然后

 $requete = $bdd -> prepare('INSERT INTO users   (prenom,nom,anniversaire,genre,email,password,role) VALUES(?,?,?,?,?,?,?)');


$requete -> execute(array($first_name ,$last_name,$birthday,.....)); 

But you will have to check if first_name, last_name or birthday variables are.== null.但是您必须检查 first_name、last_name 或birthday 变量是否为.== null。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误未捕获 PDOException:SQLSTATE [HY093]:参数编号无效:绑定变量的数量与 ..(路径)中的标记数量不匹配 - Error Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in.. (path) 未捕获的 PDOException:SQLSTATE[HY093]:无效的参数号:绑定变量的数量与标记的数量不匹配 - Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens 未捕获的 PDOException:SQLSTATE[HY093]:无效的参数号:绑定变量的数量与标记的数量不匹配 - Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens 错误:SQLSTATE[HY093]:无效的参数号:绑定变量的数量与标记的数量不匹配 - ERROR: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens SQLSTATE [HY093]:无效的参数号:绑定变量数与令牌数不匹配错误 - SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens error PDO 错误:SQLSTATE[HY093]:无效参数号:绑定变量数与令牌数不匹配 - PDO Error: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens {&quot;status&quot;:{&quot;error&quot;:&quot;SQLSTATE[HY093]: Invalid parameter number: number of bound variables not match number of tokens&quot;}} - {"status":{"error":"SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens"}} SQL 错误:SQLSTATE[HY093]:无效参数号:绑定变量数与令牌数不匹配 - SQL ERROR: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens 致命错误:带有消息&#39;SQLSTATE [HY093]的未捕获异常&#39;PDOException&#39;:参数号无效:没有参数被绑定 - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound PHP致命错误:消息为&#39;SQLSTATE [HY093]的未捕获异常&#39;PDOException&#39;:无效的参数编号: - PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM