Place ID in foreign key table

Asked

Viewed 62 times

0

'Cause I can’t get the ID on my table foreign key last_insert_id() returning "0"

<html>
<head>
<meta http-equiv="content-Type" content="text/html"; charset="utf-8" />
<title>cadastrando</title>
</head>

<body>

<?php
$saldo=$_POST['saldo'];
$limiteSaqueDiario=$_POST['limiteSaqueDiario'];
$flag=$_POST['flag'];
$tipoConta=$_POST['tipoConta'];
$dataCriacao=$_POST['dataCriacao'];

$nome="nome";
$cpf="cpf";
$dataNascimento="dataNascimento";

$sql="insert into pessoa (nome,cpf,dataNascimento) value ('$nome','$cpf','$dataNascimento')";
$result=mysql_query($sql);

$sqlconta="insert into conta (idPessoa,saldo,limiteSaqueDiario,flag,tipoConta,dataCriacao) value (last_insert_id(),'$saldo','$limiteSaqueDiario','$flag','$tipoConta','$dataCriacao')";
$result=mysql_query($sqlconta);


?>
</body>
</html>
  • Remembering that the functions mysql are obsolete

  • Easy, your SQL is giving error when inserting pessoa and so there is no ID to insert into conta ;)

  • I have 2 tables an account and another person I want to put the idpessoa in my table account I already made the key but it is not inserting when I put the function last_insert_id() it gives 0 in my table that is found foreign idpessoa in table account

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.