【发布时间】:2015-03-13 21:21:06
【问题描述】:
我的 INSERT PDO 语句有问题:
在同一个 PHP 页面中,我有这个第一个 INSERT :
//Creation d'un entrainement
if (isset($_POST) && isset($_POST['intitule_ent']) && isset($_POST['start_ent'])) {
if(get_magic_quotes_gpc()){
$_POST['intitule_ent'] = stripslashes(trim($_POST['intitule_ent']));
}
$intitule = $_POST['intitule_ent'];
if($i = $bdd->prepare("INSERT INTO entrainements (intitule_entrainement,id_membre) VALUES (:intitule_entrainement,:id_membre)")){
$i->bindParam(':intitule_entrainement', $intitule);
$i->bindParam(':id_membre', $user_id);
$i->execute();
echo '<span class="label label-success">Entrainement créé avec succès!</span>';
$entrainement_commence = true;
}
else {
echo '<span class="label label-danger">Erreur lors de la création de l\'entraînement.</span>';
}
}
这个 INSERT 效果很好!
但问题是这个 INSERT 不起作用:
//Verifications d'usage du formulaire et securite
if (isset($_POST['exm']) && isset($_POST['series']) && isset($_POST['repetitions']) && isset($_POST['valider'])) {
//On securise les chaines de caracteres pour eviter les injections
if(get_magic_quotes_gpc()){
$_POST['repetitions'] = stripslashes(trim($_POST['repetitions']));
$_POST['poids'] = stripslashes(trim($_POST['poids']));
$_POST['temps'] = stripslashes(trim($_POST['temps']));
$_POST['force'] = stripslashes(trim($_POST['force']));
$_POST['vitesse'] = stripslashes(trim($_POST['vitesse']));
}
$id_exom = $_POST['exm'];
$s = $_POST['series'];
$r = $_POST['repetitions'];
$p = $_POST['poids'];
$t = $_POST['temps'];
$f = $_POST['force'];
$v = $_POST['vitesse'];
if($i = $bdd->prepare("
INSERT INTO exercices (id_entrainement,id_exercice_muscle,membre,series,reps,poids,temps,force_exo,vitesse)
VALUES (:id_entrainement,:id_exercice_muscle,:membre,:series,:reps,:poids,:temps,:force_exo,:vitesse)")
){
$i->bindParam(':id_entrainement', $id_ent_en_cours);
$i->bindParam(':id_exercice_muscle', $id_exom);
$i->bindParam(':membre', $user_id);
$i->bindParam(':series', $s);
$i->bindParam(':reps', $r);
$i->bindParam(':poids', $p);
$i->bindParam(':temps', $t);
$i->bindParam(':force_exo', $f);
$i->bindParam(':vitesse', $v);
$i->execute();
$envoi_succes = '<span class="label label-success">Enregistrement réalisé avec succès !</span>';
}
else {
$envoi_erreur = '<span class="label label-warning">Erreur lors de l\'enregistrement de l\'exercice.</span>';
}
根据我的表架构,我真的不知道为什么它不起作用:
这是我的数据库:
我在这里给你我的表格,但我认为它不是很有用......:
<form name="envoi_exo" action="send.php" method="post">
<input type="text" name="exm" disabled value="">
<input type="text" name="series" disabled value="">
<input type="text" name="repetitions" disabled value="">
<input type="text" name="poids" disabled value="">
<input type="text" name="temps" disabled value="">
<input type="text" name="force" disabled value="">
<input type="text" name="vitesse" disabled value="">
<button type="submit" name="valider" class="btn btn-success">Enregistrer l\'exercice</button>
</form>
最后,我在 StackOverflow 上找到了一些关于 PDO 中的 INSERT 问题的主题,我尝试使用 try catch(不推荐)找到解决方案并打开我的 MYSQL 日志文件。以下是最新日志:
2015-03-13 21:36:01 6916 [Warning] InnoDB: Cannot open table phpmyadmin/pma_usergroups from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
2015-03-13 21:52:57 6916 [Warning] InnoDB: Cannot open table phpmyadmin/pma_usergroups from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
2015-03-13 21:52:57 6916 [Warning] InnoDB: Cannot open table phpmyadmin/pma_usergroups from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.
我真的需要帮助来纠正这个问题,因为我一次又一次地搜索解决方案,但我没有发现任何真正有用的...
当我单击按钮发送表单时,会出现注释并且页面只是重新加载(我认为这是操作属性),并且我没有在数据库中看到插入。
【问题讨论】:
-
大部分表单输入都有
disabled。禁用的输入不会在表单提交时发送,所以if (isset($_POST['exm']) && isset($_POST['series']) && isset($_POST['repetitions']) && isset($_POST['valider']))将是错误的。