[SQL] Insérer des données dans une table
Je reviens à la charge avec un problème similaire mais avec un message d'erreur différent.
voici le message d'erreur
Citation:
Cannot add or update a child row : a foreign key constraint fails ('gestionconferences/conference', CONSTRAINT 'conference_ibfk_1' FOREIGN KEY ('IdUniv') REFERENCES 'universite' (IdUniv'))
voici les codes
Code:
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
|
<!--Inserer une conférence-->
<html>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td rowspan="2" bgcolor="#666666"> <img src="" name="image" width="100" height="50">
</td>
<td width="100%" bgcolor="#666666"><font color="#CCCCCC"><h1> Gestion de conférences </h1></font>
</td>
</tr>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="100%" bgcolor="red"font color="#CCCCCC">  </font>
</td>
</tr>
</table>
<?php
require("connect1.php");
$selectIdUniv=mysql_query("select * from universite");
echo"<table border=0 >";
echo"<form action='inserer_Conf.php' method=POST>";
echo"<tr> <td >IdConf<td><input type='text' name='IdConf' ></tr>";
echo"<tr> <td width=15%>Intitule<td><textarea cols=80 rows=4 name='intitule'></textarea></tr><br>";
echo"<tr> <td >dateSoumission<td><input type='text' name='dateSoumission' ></tr>";
echo"<tr> <td >dateAcceptation<br><td><input type='text' name='dateAcceptation'></tr>";
echo"<tr> <td >dateFin<td><input type='text' name='dateFin'><td></tr>";
echo"<tr> <td >droitInsc<td><input type='text' name='droitInsc'></tr>";
echo"<tr> <td >NbArtMax<td><input type='text' name='nbArtMax'></tr>";
echo"<tr> <td >IdUniv<td><select name='IdUniv'>";
while($idUniv=mysql_fetch_object($selectIdUniv)){
echo"<option value='IdUniv' name='idUniv'>$idUniv->IdUniv</option>";
}
echo" </select></tr>";
echo"</table>";
echo"<input type='submit' value='Envoyer' name='envoyer'><input type='reset' value='Réinitialiser' name='reinitialiser'>";
echo"</form>";
?>
</body>
</html> |
et
Code:
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
|
<?php
require("connect1.php");
$IdConf=$_POST["IdConf"];
$intitule=$_POST["intitule"];
$dateSoumission=$_POST["dateSoumission"];
$dateAcceptation=$_POST["dateAcceptation"];
$dateFin=$_POST["dateFin"];
$droitInc=$_POST["droitInsc"];
$nombreArtMax=$_POST["nombreArtMax"];
$envoyer=$_POST["envoyer"];
$iduniv=$_POST["idUniv"];
if($envoyer){
$selectIdUniv=mysql_query("select * from universite WHERE IdConf=$IdConf");
$insertConf=mysql_query("INSERT INTO conference (IdConf,Intitule,DateSoumission,DateAcceptation,DateFin,DroitInsc,NbArtMax,IdUniv) VALUES('$IdConf','$intitule','$dateSoumission','$dateAcceptation','$dateFin','$droitInc','$nombreArtMax','$iduniv')")or die("problème de requete insertion dans conference:".mysql_error());
#mysql_query("INSERT INTO universite (idUniv) VALUES($iduniv)")or die("problème de requete table université:".mysql_error());
}
?>
<script language="javascript" type="text/javascript">
<!--
window.location.replace("espaceModifConf.php");
-->
</script> |
en effet IdUniv est clé étrangère dans la table "conference" et clé primaire dans "université".