sorry im not really expert on mysql.
i have table transactions(Trans_ID is PK but not Auto increment) but have transactionseq to trigger auto increment.
on table transactions i put trigger to get Trans_ID from table transactionseq
here below trigger code :
CREATE
DEFINER=`root`@`localhost`
TRIGGER `pos`.`tg_transactions_insert`
BEFORE INSERT ON `pos`.`transactions`
FOR EACH ROW
BEGIN
INSERT INTO transactionseq VALUES (NULL);
SET NEW.ID_Transaction = CONCAT('IDT', LPAD(LAST_INSERT_ID(), 3, '0'));
END$$
and i have php code for insert to my table here the code :
if($_SERVER['REQUEST_METHOD']=="POST"){
$response = array();
$ID_Employee = $_POST['ID_Employee'];
$Name_Employee = $_POST['Name_Employee'];
$ID_Customer = $_POST['ID_Customer'];
$Table_Number = $_POST['Table_Number'];
$insert = "INSERT INTO transactions
(ID_Employee,Name_Employee,ID_Customer,Table_Number,ID_Outlet,CreatedBy_Transaction,CreatedDate_Transaction,Status_Transaction)
VALUES ('".$ID_Employee."','".$Name_Employee."','".$ID_Customer."','".$Table_Number."','1','".$ID_Employee."',NOW(),'OPEN')";
if(mysqli_query($con, $insert)){
$last_ID = mysqli_insert_id($con);
$response['value']=1;
$response['message']="Table berhasil dimulai".$last_ID;
echo json_encode($response);
}
else{
$response['value']=0;
$response['message']="Table gagal dimulai";
echo json_encode($response);
}
}
since my table transaction have a trigger and no auto increment so i cant get the last Trans_ID by using mysqli_insert_id($con).
please your advice how to get my last insert Trans_ID?and will passing this Trans_ID to my flutter app.
Thank you