I have a problem that I can not solve.
Ahem: table 1 and table 2, in table 1 I have already registered the user and this one is already with the session started with id1. In table 2 I'm trying to insert the id1 and other information of another form.
To explain myself better I am trying to select a primary key and insert this in another table as a foreign key, since the user is already logged in.
I already look for information in the php manual but I can not make the INSERT_ID()
OR LAST_INSERT_ID
work always presents me with an error.
<?php
session_start();
require'funcs/conexion.php';
$cpf = $_POST['cpf'];
$numero =$_POST['numero'];
$nomebanco = $_POST['nomebanco'];
$agencia =$_POST['agencia'];
$conta=$_POST['conta'];
$idUsuario = $_SESSION['id_usuario'];
$selecionaid = "SELECT * FROM usuarios WHERE id='$idUsuario'";
$result = $mysqli->query($selecionaid);
$sql = "INSERT INTO tbbancarios (cpf, numero, nomebanco, agencia, conta) VALUES ('#cpf', '$numero', '$nomebanco', '$agencia', '$conta', '$result')";
$resultado = $mysqli->query($sql);
if ($resultado) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($mysqli);
}
mysqli_close($con);
?>