Click here to Skip to main content
15,887,988 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
Hi everyone, I'm new to PHP, so I need help from your.
Currently I have 2 table for database Customer and Login.

Table Customer (CustID, CustName, Phone) CustID primary key, auto increment.
Table Login (Email, Password, CustID) Email Primary key,
 CustID Foreign key to table Customer

Now, I can insert all the detail into table customer, but I can't insert any data into table login, it shows the Error "<i>PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xampp\htdocs\Assignment\suSuccess.php on line 74"</i>



PHP
//Connection
try {
            $dbhost = 'localhost';
            $dbuser = 'root';
            $dbpass = '';
            $dbname = "pizza";
            $odb = new PDO("mysql:host=" . $dbhost . ";dbname=" . $dbname, $dbuser, $dbpass);
        } catch (PDOException $ex) {
            echo $ex->getMessage();
            exit();
        }

            $q = "INSERT INTO customer (`CustName`, `DOB`, `Address`, `Phone`) VALUES (:name, :dob, :address, :phone)";
            $query = $odb->prepare($q);
            $result = $query->execute(array(
                ":name" => $name,
                ":dob" => $dob,
                ":address" => $address,
                ":phone" => $phone
            ));
            
            if ($result > 0) {
                $id = $odb->lastInsertId();
                $q2 = "INSERT INTO login (`Email`,`Password`,`CustID`) VALUES (:email, :password,:custid)";
                $query2 = $odb->prepare($q2);
                $result2 = $query2->execute(array(
                    ":email" => $email,
                    ";password" => $password,
                    ":custid" => $id
                )); //<----- Here is the error
                echo $odb->lastInsertId();
                if ($result2 > 0) {
                    echo "Sucess";
                } 
                else {
                    echo "Fail";
                }
            } else {
                echo "Fail";
            }


What I have tried:

I not sure whether the code is correct or not to insert data into my login table.
Posted
Updated 15-Jul-16 4:11am

You have a typo in your parameter array:
PHP
";password" => $password,

The parameter name should start with a colon (:), but it currently starts with a semi-colon (;).

However, you shouldn't be storing passwords in plain text. You should only ever store a salted hash of the user's password, using a unique salt per record:
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
 
Share this answer
 
Comments
Zhe Yong 15-Jul-16 22:47pm    
Thank You, i have made this mistake.
you forgot the password parameter in your connection string,
PHP Prepared Statements[^]
 
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