bonjour à tous,
l'analyse est simple, 3 tables : photos, photo_theme, themes. en clair plusieurs photos peuvent avoir plusieurs themes.

Je doit créer une formulaire dans lequel je puisse ajouter les informations d'une photo et également les thèmes auquels elle appartient. Et tout ça sur une seule page appeler insert.php

mon problème est le suivant. L'ajout se fait bien dans la table photos mais pas photo_theme. Voila le code

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
if(isset($_POST['insert']))
{
	//COMPTEUR POUR NUM_PHOTO
	$sql = "SELECT MAX( NUM_PHOTO ) AS maxphoto FROM photos;";
 
	$exec = mysql_query($sql, $connec) or die("erreur -> ".mysql_error());
 
	if($ligne = mysql_fetch_array($exec))
	{
		$num = $ligne['maxphoto'] + 1;
	}
 
 
 
	   //RECUPERATION DONNEES FORMULAIRES
                $nom = $_POST['nom'];
	   $photographe = $_POST['photographe'];
	   $lieu = $_POST['lieu'];
	   $commune = $_POST['commune'];
	   $copyright = $_POST['copyright'];
 
	   $mois = $_POST['mois'];
	   $jour = $_POST['jour'];
	   $annee = $_POST['annee'];
	   $d = mktime(0,0,0,$mois,$jour,$annee);
	   $dateprise = date("Y-m-d",$d); 
 
	   //INSERTION DANS LA TABLE photos
		$query="INSERT INTO photos (NUM_PHOTO, PHOTOGRAPHE, NOM_PHOTO, LIEU_DIT, COMMUNE, DATE, COPYRIGHT, CHEMIN) "
		."VALUES (".$num.", '$photographe', '$nom', '$lieu', '$commune', '$dateprise', '$copyright', '$fichier');";
 
		$exec=mysql_query($query,$connec) or die("erreur -> ".mysql_error());
 
		//INSERTION DANS LA TABLE photo_theme
		foreach ($_POST  as $cle=>$valeur)
		{	
			if ($cle!='insert')
			{			
				$query="INSERT INTO photo_theme (NUM_THEME, NUM_PHOTO) "
				."VALUES (".$cle.", $num);";
				echo $cle;
				$exec=mysql_query($query,$connec) or die("erreurcoucou -> ".mysql_error());
			}
		}
 
		echo "<SCRIPT LANGUAGE='JavaScript'>";
		echo "alert('La photo a bien été ajouté(e).')";
		echo "</SCRIPT LANGUAGUE>";
}