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>
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
));
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.