Hi everyone I've searched everywhere the answers and nothing's satisfying the code :/
Here's my Database Table :
1 Form_ID int(11) AUTO_INCREMENT
2 identifiant varchar(10)
3 Ch varchar(6)
4 Date date
5 Unite varchar(10)
6 Catsoin varchar(30)
7 Soin varchar(30)
8 Duree varchar(10)
9 Debutsoin time
10 Finsoin time
I make injections in my database through php Form, and my Insert works really fine. But for efficiency purpose I need to retrieve the user current Session_id
And that's were in my form I created :' $_SESSION['id']=$_POST['Identifiant'];' The problem with that use is that when a page is reloaded, the Browser creates a New session and loose by then the Session id, so this method doesn't work for me.
And that's where mysqli_insert_id() come into play.
In the Database Table I've created the AUTO_INCREMENT attribute Form_ID
, which is unique.
So I need to use mysqli_insert_id() in order to catch the unique Form_ID that is created in the very moment when a client makes an Insert.
That's were I unsuccessfully tried :
file : InsertionBD.php
<?php
include('include/connexion.php');
$query = "Insert into `formulaire`";
$id = mysqli_insert_id($connexion);
IF(isset($_POST['UnitList'])... and so on
?>
And Tried to re-catch this inserted Id Here. The If(isset()) function reacts to a input type Button, so that when the user click on it creates a reaction in the php server side and that's in this particular situation that I need the mysqli_insert_id()** to work file :** Form.php
session_start();
include('include/config.php');
include('include/connexion.php');
$id=mysqli_insert_id($connexion);
$result = mysqli_query($connexion,"SELECT `identifiant`,`Ch`,`Date` FROM `formulaire` where
`Form_ID` = '".$id."'
");
If(isset($_POST['SelectID']))
{
//$_SESSION['id'] = mysqli_insert_id($connexion); -> not working since Session reload
echo "processing...<br/>";
echo "ID of last inserted record is: ".mysqli_insert_id($connexion);
while($row = mysqli_fetch_array($result))
{
$Recupid = $row['identifiant'] ;
$RecupCh = $row['Ch'] ;
$RecupDate = $row['Date'];
echo "<br><b>Votre identifiant :</b>". $Recupid.
"<br><b> Le code horaire choisi :</b> ".$RecupCh.
"<br><b> La date de la prestation : </b>".$RecupDate.
"<br><b> L'horaire de la prestation : </b>".$debut." <b>à</b> ".$fin ;
echo "<br>";
}
}
else
{
//I used superglobal $_Sessions before this code on this page but I did not show the code to simplify the view but session works fine
echo "<b>Your ID :</b>".$_SESSION['id']."<br />";
echo "<b>Your Code horaire :</b>".$_SESSION['Code']."<br />";
echo "<b>Your Date : </b>".$_SESSION['Date']."<br />";
echo "<b>Your First Plage horaire :</b>".$_SESSION['Debut']."<br />";
echo "<b>Your Second Plage horaire :</b>".$_SESSION['Fin']."<br />";
}
The return value is :
processing... ID of last inserted record is: 0
So I understand is my mysqli_insert_id() function pointing to nothing? How can I take back the specific Form_ID please?
Thank you in advance for the help