I am making a registration page where the username and password goes to the tbl_login, and I want to put the other details like the fullname into another table named tbl_userinfo that has a foreign key which is the id of tbl_login.
$Select = "SELECT username FROM tbl_login WHERE username = ? LIMIT 1";
$Insert = "INSERT INTO tbl_login(username, password, usertype) values(?, ?, ?)";
$Insert2 = "INSERT INTO tbl_userinfo(fullname, purok, contactnumber) values(?, ?, ?)";
$stmt = $conn->prepare($Select);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($username);
$stmt->store_result();
$stmt->fetch();
$rnum = $stmt->num_rows;
if ($rnum == 0) {
$stmt->close();
//for insert into tbl_login
$stmt = $conn->prepare($Insert);
$stmt->bind_param("sss",$username, $password, $usertype);
//for insert into tbl_userinfo (i want to add this)
$stmt = $conn->prepare($Insert2);
$stmt->bind_param("sss",$fullname, $purok, $contactnumber);
if ($stmt->execute()) {
echo '<script type="text/javascript">';
echo 'window.location.href = "../loginform/index.php";';
echo 'alert("Account created! Redirecting to Login page");';
echo '</script>';
The $select and $insert already works but when I add the $insert2 query it doesn’t save in the database