Home > Enterprise >  Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number of bound variables doe
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number of bound variables doe

Time:11-14

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\server\MedFast.php:29 Stack trace: #0 C:\xampp\htdocs\server\MedFast.php(29): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\server\MedFast.php on line 29

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">

</head>
<body>
    <main >
    <?php
$username = "root";
$password = "";
$database = new PDO("mysql:host=localhost;dbname=medfast;",$username,$password);

if(isset($_POST['send'])){
$Email =$_POST['Email'];
$password =$_POST['password'];
$age =$_POST['age'];

$addData = $database->prepare("INSERT INTO Patient(Email,password,age) 
Values(':Email',':password',':age')");
$addData->bindParam("Email",$Email);
$addData->bindParam("password",$password);
$addData->bindParam("age",$age);

if ($addData->execute()){
echo' SIGNED IN';
}
else{
    echo 'Failed to sign in';
}
}
?>

<form method="POST">
Email : <input type="text" name="Email" required/>
<br>
password: <input type="int" name ="password" required/>
<br>
age: <input type="int" name ="age" required/>
<br>
<button type="submit" name="send">send</button>
</form>

    </main>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C OGpamoFVy38MVBnE IbbVYUew OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho j7jyWK8fNQe A12Hb8AhRq26LrZ/JpcUGGOn Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
</body>
</html>

i don't know what is the problem ??

CodePudding user response:

The single quotes around your params in your query are wrong.

With the following code it should work:

$addData = $database->prepare("INSERT INTO Patient(Email,password,age) 
Values(:Email, :password, :age)");
  • Related