-2
I’m new to this language, I was previously using a auto_increment
to save the ID sequentially in the bank, but found problems in other functions. My question is: How do I get the last "id" of the bank and add +1 - Follow what I was trying, but unsuccessfully:
<?php
include 'conecta_mysql.inc';
$id1 = 'SELECT LAST(id) FROM t_saida';
$id = $id1+1;
$os = $_POST['os'];
$data = $_POST['data'];
$tech = $_POST['tech'];
$descri = $_POST['descri'];
$pag = $_POST['pag'];
$valor = $_POST['valor'];
$query = "INSERT INTO t_saida (id,data,os,tech,descri,pag,valor) VALUES ('$id','$data','$os','$tech','$descri','$pag','$valor')";
if (mysqli_query($link, $query)) {
echo "Inserido com sucesso!";
echo "<script>window.open ('','_self')</script>";
} else {
echo "Erro: " . $sql . "<br>" . mysqli_error($link);
}
mysqli_close($link);
?>
Notice that I enter the data through a form, and try to increment the id with the variable $id1
and $id
.
Instead of LAST, use MAX in SQL, but you need to submit this query to return the value.
– Daniel Mendes
Submit, you speak, before entering the form data?
– Henrique
Something like this: $id1 = 'SELECT max(id) FROM t_output'; mysqli_query($link, $id1); ?
– Henrique