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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| <?php
if (isset($_POST['exercice_submit'])) {
$texte=$_POST['exercice'];
$titre=$_POST['titre'];
$commentaire=$_POST['commentaire'];
$specialite=$_POST['specialite'];
$image1=$_POST['image1'];
$image2=$_POST['image2'];
$image3=$_POST['image3'];
setlocale (LC_TIME, 'fr_FR.utf8','fra');
date_default_timezone_set('UTC');
$date=date('j/m/y');
$auteur=$_SESSION['utilisateur'];
try {
$bdd = new PDO ('mysql:host=localhost;dbname=nom_base', 'root', '');
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (Exception $e) {
die();
}
// fonctionne bien
$exec=$bdd->prepare('INSERT INTO liste_exercices (auteur, date, titre, commentaire) VALUES (?, ?, ?, ?)');
$exec->execute(array($auteur, $date, $titre, $commentaire));
for ($i=1;$i<17;$i++) {
if (!empty($_POST['question'.$i.''])) {
${'question'.$i} = $_POST['question'.$i.''];
// PDOException : SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''question(1)') VALUES ('Intitulé 1')' at line 1' in C:\wamp\www\Dossier\saisie_exercice.php on line 34
$exec=$bdd->prepare('INSERT INTO liste_exercices (:question) VALUES (:question_value)');
$exec->bindValue(':question', "question($i)", PDO::PARAM_STR);
$exec->bindValue(':question_value', ${'question'.$i}, PDO::PARAM_STR);
$exec->execute();
echo "${'question'.$i}"; // vérification de la valeur de la variable (s'affiche correctement)
echo "question($i)"; // vérification de l'affichage du paramètre (correct)
}
if (!empty($_POST[''.$i.'a']) AND !empty($_POST[''.$i.'b']) AND !empty($_POST[''.$i.'c']) AND !empty($_POST[''.$i.'d']) AND !empty($_POST[''.$i.'e'])) {
${$i.'a'}=$_POST[''.$i.'a'];
${$i.'b'}=$_POST[''.$i.'b'];
${$i.'c'}=$_POST[''.$i.'c'];
${$i.'d'}=$_POST[''.$i.'d'];
${$i.'e'}=$_POST[''.$i.'e'];
${'items('.$i.')'}=${$i.'a'}.'-'.${$i.'b'}.'-'.${$i.'c'}.'-'.${$i.'d'}.'-'.${$i.'e'}; // création d'une chaîne englobant les 5 items avec le séparateur " - " pour les séparer plus tard
echo "${'items('.$i.')'}"; // vérification affichage de la valeur de la variable (correct)
echo "items($i)"; // vérification affichage du paramètre (correct)
// PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\wamp\www\Dossier\saisie_exercice.php on line 56
$exec=$bdd->prepare('INSERT INTO liste_exercices (:items) VALUES (:items_value)');
$exec->bindValue(':items', "items($i)", PDO::PARAM_STR);
$exec->bindValue(':items', ${'items('.$i.')'}, PDO::PARAM_STR);
$exec->execute();
}
}
}
?> |
Partager