Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am geting "!Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined." while trying to insert data in local host phpmyadmin. Here is my source code.

What I have tried:

<?php
include_once('config.php');
if(isset($_POST['submit']))
{   
    $uname = $_POST['nm'];
    $uaddress = $_POST['add'];
    $uemail = $_POST['em'];
    $ugender = $_POST['gen'];
    $udob = $_POST['dob'];
    $udeg = $_POST['des'];
    $upass = $_POST['pass'];

//Insertion of values in an array
    $data = [
        'name' => $uname,
        'addr' =>  $uaddress,
        'email' => $uemail,
        'gender' => $ugender,
        'dob' => $udob,
        'degi' => $udeg

    ];

    //Prepairing SQL insert query
    $sql = "INSERT INTO users (name, address, email, gender, date_of_birth, designation) VALUES (:name, :addr, :email, :gender, :dob, :deg )";
    $stmt = $conn->prepare($sql);
    $stmt->execute($data);
}
?>
Posted
Updated 10-Mar-21 1:47am
v2
Comments
Richard Deeming 10-Mar-21 10:32am    
Based on the variable names, it looks like you are storing your users' passwords in plain text. Don't do that.
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

PHP even has built-in functions to help you do it properly:
PHP: password_hash[^]
PHP: password_verify[^]

1 solution

You have not defined the parameter "deg". In your data object you have it as "degi".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900