1
I need to get the ID of the entity that has just been registered. Only it will be played to another screen, to be registered other information. I would like to know how I can get the entity ID when saving the form.
This is the HTML
<form action="set.php" method="post">
<div class="col-md-6">
<div class="form-group">
<label class="control-label">*Nome</label>
<input type="text" id="nome" name="nome" class="form-control" placeholder="">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="control-label">Sobrenome</label>
<input type="text" id="sobrenome" name="sobrenome" class="form-control" placeholder="">
</div>
</div>
And this is PHP
<?php
$nome = $_POST ["nome"];
$sobrenome = $_POST ["sobrenome"];
$sql = mysql_query ("INSERT INTO gr_entidade (nome, sobrenome ) VALUES ('$nome', '$sobrenome')");
header("Location: usuario?id=id");
?>
header("Location: usuario?id=id");
Can you give me a hand ?
mysql_insert_id - Gets the ID generated by the previous INSERT operation http://php.net/manual/en/function.mysql-insert-id.php
– user60252
LAST_INSERT_ID - only works if you made the last insertion on the same connection. If the last insert added 3 records in DB, this function returns the first of them, not the last. https://answall.com/questions/127456/forma-otimizada-recuperar-ultimo-id-mysql
– user60252
Do
header("Location: outrapagina.php?id=" . mysql_insert_id());
and on the other page receive so<div><?php echo $_GET['id']; ?></div>
– Juven_v