Good day, from a php form I am capturing the information in phpmyadmin.
In the background is the realization of a purchase that when stored in the database increases the purchase number (purchase 1, 2, 3 etc.).
I have reviewed the code several times and I have not been able to find the error that makes each one make a purchase with the same number. That is, every purchase I make is saved with the same purchase number instead of the purchase number increasing .
I thank you in advance for your help.
<?php
session_start();
include "verbindung.php";
$arreglo=$_SESSION['car'];
$numeroventa=0;
$re=mysqli_query($verbindung,"select * from bestellposition order by verkauf_num DESC limit 1") or die(mysqli_error($verbindung));
while ( $f=mysqli_fetch_array($re)) {
$numeroventa=$f['Verkauf_num'];
$datum=$f['Datum'];
}
if($numeroventa==0){
$numeroventa=1;
}else{
$numeroventa=$numeroventa+1;
}
for($i=0; $i<count($arreglo); $i++){
mysqli_query($verbindung,"insert into bestellposition (verkauf_num,Kunde_ID,Produkt_ID,Menge,name,Summe) values(
".$numeroventa.",
'".$_SESSION['Kunde_ID']."',
'".$arreglo[$i]['produkt_id']."',
'".$arreglo[$i]['menge']."',
'".$arreglo[$i]['name']."',
'".($arreglo[$i]['preis']*$arreglo[$i]['menge'])."'
)")or die(mysqli_error($verbindung));
}
for($i=0; $i<count($arreglo);$i++){
mysqli_query($verbindung,"insert into rechnung (bestellposition_ID,Bestellung_Datum) values(
".$numeroventa.",
'".$datum."'
)")or die(mysqli_error($verbindung));
}
unset($_SESSION['car']);
header("Location: resume_einkauf.php");
?>