Bonjour,

Je réalise une base de données de stages d'étudiants et j'ai créé les 4 bases suivantes : etudiant (avec ID en clé primaire auto-incrémenté), stage1a, stage2a et enfin stage 3a.
J'ai créé également une page pour l'insertion de nouvelles données dans ma base.
Voici un extrait du code que j'utilise pour cette page :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
 $insertSQL = sprintf("INSERT INTO etudiant (nom, prenom, promotion, mail, tel, info) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['nom'], "text"),
                       GetSQLValueString($_POST['prenom'], "text"),
                       GetSQLValueString($_POST['promotion'], "text"),
                       GetSQLValueString($_POST['mail'], "text"),
                       GetSQLValueString($_POST['tel'], "text"),
                       GetSQLValueString($_POST['info'], "text"));
 
  mysql_select_db($database_ConnexionStages, $ConnexionStages);
  $Result1 = mysql_query($insertSQL, $ConnexionStages) or die(mysql_error());
 
  $insertSQL = sprintf("INSERT INTO stage1a (societe, adresse, ville, departement, pays, tel, fax, datedebut, datefin, maitre, theme, tuteur, confidentialite, info) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ",
                       GetSQLValueString($_POST['societe1A'], "text"),
                       GetSQLValueString($_POST['adresse1A'], "text"),
                       GetSQLValueString($_POST['ville1A'], "text"),
                       GetSQLValueString($_POST['dep1A'], "text"),
                       GetSQLValueString($_POST['pays1A'], "text"),
                       GetSQLValueString($_POST['tel1A'], "text"),
                       GetSQLValueString($_POST['fax1A'], "text"),
                       GetSQLValueString($_POST['datedebut1A'], "text"),
                       GetSQLValueString($_POST['datefin1A'], "text"),
                       GetSQLValueString($_POST['maitre1A'], "text"),
                       GetSQLValueString($_POST['theme1A'], "text"),
                       GetSQLValueString($_POST['tuteur1A'], "text"),
                       GetSQLValueString($_POST['confidentialite1A'], "text"),
                       GetSQLValueString($_POST['info1A'], "text"));
Dans mes bases stages j'ai une ligne etudiantID et j'aimerais que lors de l'insertion d'une donnée cette ligne prenne la valeur de l'ID nouvellement incrémenté de la table etudiant.
On m'a parlé de la fonction LAST_INSERT_ID(), pourriez-vous me dire comment l'utiliser dans mon code ?