Bonjour à tous,

Sur mon site de présentation de films documentaires, je propose aux administrateurs de saisir et d'éditer les docs via des formulaires qui contiennent, entre autres, des checkboxes qui prennent leurs informations dans la BDD.

Ci-dessous les informations utiles à la construction d'une de ces checkboxes, celle concernant le format d'un doc.


Tables :

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
58
59
60
-- --------------------------------------------------------
--
-- Structure de la table documentaire 
--
 
CREATE TABLE IF NOT EXISTS documentaire (
  idDoc int (3) NOT NULL AUTO_INCREMENT, 
  ...
  CONSTRAINT pk_documentaire
		PRIMARY KEY (idDoc),
  ...
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
 
-- --------------------------------------------------------
--
-- Structure de la table formaDoc 
--
 
CREATE TABLE IF NOT EXISTS formaDoc (
  idFormDoc varchar(4) NOT NULL,
  nomFormDoc_fr varchar(255) NOT NULL,
  nomFormDoc_en varchar(255) NOT NULL,
  CONSTRAINT pk_formaDoc
		PRIMARY KEY (idFormDoc)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
 
--
-- Contenu de la table formaDoc
--
 
INSERT INTO formaDoc (idFormDoc, nomFormDoc_fr, nomFormDoc_en) VALUES
('fbsp' , 'Beta SP', 'Beta SP'),
('fbnu' , 'Beta numérique' , 'Digital betacam'),
('fthd' , 'THDVD' , 'THDVD'),
('fs16' , 'Super 16 mm' , 'Super 16 mm'),
('fv16' , 'Vidéo et 16 mm' , 'Video and 16 mm'),
('fdvc' , 'DV Cam' , 'DV Cam'),
('f16m' , '16 mm' , '16mm'),
('fhdc' , 'HD Cam' , 'HD Cam');
 
--
-- Structure de la table `docDisposeFormat`
--
 
CREATE TABLE IF NOT EXISTS `docDisposeFormat` (
  `idDoc` int(3) NOT NULL DEFAULT '0',
  `idFormDoc` varchar(4) NOT NULL DEFAULT '',
  PRIMARY KEY (`idDoc`,`idFormDoc`),
  KEY `fk_docDisposeFormat_idFormDoc` (`idFormDoc`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
--
-- Contenu de la table `docDisposeFormat`
--
 
INSERT INTO `docDisposeFormat` (`idDoc`, `idFormDoc`) VALUES
(38, 'f16m'),
...
(90, 'fbsp'),
(90, 'fv16');
php pour l'insert de la checkbox format :

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
<?php
// ***** récup checbox formaDoc ***** 	
$idDocumentaire=mysql_insert_id(); // La valeur de l'index attribué au document.
 
$choixFormaDoc=Array();
if(isset($_POST['formaDoc'])) { // Envoie du formulaire...
	$choixFormaDoc=$_POST['formaDoc'];
	$sql="INSERT INTO docDisposeFormat (idDoc,idFormDoc) VALUES";
 
	foreach($choixFormaDoc AS $choix) $sql.="(".$idDocumentaire.",'".$choix."'),"; // On enregistre chaque choix dans la table en indiquant l'idDoc du choix
	if(mysql_query(substr($sql,0,strlen($sql)-1)))
		echo "Enregistré!";
	else echo "Non enregistré: (".$sql.") ".mysql_error();
}
 
function coche($val)
{ // Retourne checked si la valeur a été coché... :
	global $choixFormaDoc;
	return (in_array($val,$choixFormaDoc)?"checked":"");
}
et maintenant, le php qui ne fonctionne pas pour l'update de cette satanée checkbox :

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
<?php
// ***** update checkbox formaDoc ***** 
$choixFormaDoc=Array();
if(isset($_POST['formaDoc'])) { // Envoie du formulaire...
	$choixFormaDoc=$_POST['formaDoc'];
	//$idFormDoc=$_POST['idFormDoc'];
 
	$sqlUpdateFormat=("
	UPDATE docDisposeFormat SET
	idDoc = '',
	idFormDoc = ''
	");
 
	echo 'idDoc='.$idDoc.'<br/>';
 
	foreach($choixFormaDoc AS $choix) $sqlUpdateFormat.="(".$idDoc.",'".$choix."'),"; // On enregistre chaque choix dans la table en indiquant l'idDoc du choix
	if(mysql_query(substr($sqlUpdateFormat,0,strlen($sqlUpdateFormat)-1)))
		echo "Enregistré!";
	else echo "Non enregistré: (".$sqlUpdateFormat.") ".mysql_error();
}
 
function coche($val)
{ // Retourne checked si la valeur a été coché... :
	global $choixFormaDoc;
	return (in_array($val,$choixFormaDoc)?"checked":"");
}
Voici ce que ça m'affiche pour le doc 78 pour lequel j'ai coché les cases f16m et fs16 :
idDoc=78
Non enregistré: ( UPDATE docDisposeFormat SET idDoc = '', idFormDoc = '' (78,'f16m'),(78,'fs16'),) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(78,'f16m'),(78,'fs16')' at line 4
C'est donc manifestement la syntaxe de ma requête SQL qui merdouille...

Merci d'avance de vos conseils.