Bonjour,
Voici l'erreur qui apparait lorsque j'essaie d'inserer les infos dans une table de ma base des données.
Erreur SQL !INSERT INTO 'site' ('id' ,'idsiteinterne' ,'idsiteprovider' ,'idsurvey' ,'dateactivation' ,'dateinstallation' ,'adressesite' ,'idclient' ,'adresseIP' ,'adresseIPmanage' ,'emailsite' ,'idprovider' ,'idetatsite' ,'idpays' ,'matriculeSite' ,'telephone' ,'observation' ,'datecreation') VALUES(NULL, "CYB001", "CYB001", "CYB001", "2", "2", "Kinshasa, Mont-ngafula", "CYB001", "192.168..52", "192.168.0.5", "glodybiss@gmail.com", "CYB001", "CYB001", "Activé", "CYB001", "0998226612", "message", "2011-11-21 09:41:08")
Cannot add or update a child row: a foreign key constraint fails ('cybernet'.'site', CONSTRAINT 'fk_site_provider' FOREIGN KEY ('idprovider') REFERENCES 'provider' ('id') ON DELETE NO ACTION ON UPDATE NO ACTION)
Voici mon code php
<?php
$serveur = getenv("SERVER_NAME");
$chez_moi=($serveur=="localhost");
if($chez_moi)include_once 'cfg.php';
else include_once 'cfg2.php';
if (isset($_POST['Enregistrer']) && $_POST['Enregistrer'] == 'Enregistrer' ) {
if ((isset($_POST['dateinstallation']) && !empty($_POST['dateinstallation'])) && (isset($_POST['dateactivation']) && !empty($_POST['dateactivation']))
&& (isset($_POST['adressesite']) && !empty($_POST['adressesite'])) && (isset($_POST['idclient']) && !empty($_POST['idclient']))
&& (isset($_POST['adresseIP']) && !empty($_POST['adresseIP'])) && (isset($_POST['adresseIPmanage']) && !empty($_POST['adresseIPmanage']))
&& (isset($_POST['emailsite']) && !empty($_POST['emailsite'])) && (isset($_POST['idprovider']) && !empty($_POST['idprovider']))
&& (isset($_POST['matriculeSite']) && !empty($_POST['matriculeSite']))&& (isset($_POST['idetatsite']) && !empty($_POST['idetatsite']))
&& (isset($_POST['observation']) && !empty($_POST['observation'])) )
{
if ($_POST['idsiteinterne'] == $_POST['idsiteprovider']) {
$erreur = 'Les ID provider et interne sont indentique';
}
if ($_POST['idsurvey'] != $_POST['idsiteinterne']) {
$erreur = 'Les ID survey et interne sont differents';
}
else {
$base = mysql_connect (DB_HOST, USER_NAME, PASSE_WORD);
mysql_select_db (DATA_BASE, $base);
$sql = 'SELECT count(*) as nb FROM site WHERE idclient ="'.mysql_escape_string($_POST['idclient']).'"';
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$data = mysql_fetch_array($req);
if ($data['nb'] == 0) {
$sql = 'INSERT INTO 'site' ('id' ,'idsiteinterne' ,'idsiteprovider' ,'idsurvey' ,'dateactivation' ,'dateinstallation' ,'adressesite' ,'idclient' ,'adresseIP' ,'adresseIPmanage' ,'emailsite' ,'idprovider' ,'idetatsite' ,'idpays' ,'matriculeSite' ,'telephone' ,'observation' ,'datecreation') VALUES(NULL, "'.mysql_escape_string($_POST['idsiteinterne']).'", "'.mysql_escape_string($_POST['idsiteprovider']).'", "'.mysql_escape_string($_POST['idsurvey']).'",
"'.mysql_escape_string($_POST['dateinstallation']).'", "'.mysql_escape_string($_POST['dateactivation']).'",
"'.mysql_escape_string($_POST['adressesite']).'", "'.mysql_escape_string($_POST['idclient']).'",
"'.mysql_escape_string($_POST['adresseIP']).'", "'.mysql_escape_string($_POST['adresseIPmanage']).'",
"'.mysql_escape_string($_POST['emailsite']).'", "'.mysql_escape_string($_POST['idprovider']).'",
"'.mysql_escape_string($_POST['matriculeSite']).'", "'.mysql_escape_string($_POST['idetatsite']).'",
"'.mysql_escape_string($_POST['matriculeSite']).'", "'.mysql_escape_string($_POST['telephone']).'",
"'.mysql_escape_string($_POST['observation']).'", "'.date('Y-m-d h:i:s').'")';
mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error());
session_start();
$_SESSION['nom'] = $_POST['nom'];
header('Location: '.PAGE_PRIVATE.'');
exit();
}
else {
$erreur = 'Cet utilisateur existe deja dans le systeme';
}
}
}
else {
$erreur = 'Au moins un des champs est vide.';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Nouveau site| Support AppManga Cybernet </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="news_client_site">
<form action="" method="post" name="form1" id="form1">
<form action="includes/chek_achat.php" method='post' onSubmit="return(VerifForm(this))">
<table width="350" border="0" class="left">
<?php
if (isset($erreur)) {
echo '<div id="info" class="error">'.$erreur.'</div><!--error-->';
} ?>
<h3>Nouveau site</h3>
<tr>
<td class="td">ID Site interne </td>
<td> <input type="text" name="idsiteinterne" class="input_ajout_agent" value="<?php if (isset($_POST['idsiteinterne'])) echo htmlentities(trim($_POST['idsiteinterne'])); ?>" ></td>
</tr>
<tr>
<td>ID Site Provider</td>
<td >
<input type="text" name="idsiteprovider" class="input_ajout_agent" value="<?php if (isset($_POST['idsiteprovider'])) echo htmlentities(trim($_POST['idsiteprovider'])); ?>" ></td>
</tr>
<tr>
<td>ID Site survey</td>
<td >
<input type="text" name="idsurvey" class="input_ajout_agent" value="<?php if (isset($_POST['idsurvey'])) echo htmlentities(trim($_POST['idsurvey'])); ?>" ></td>
</tr>
<td>Date activation</td>
<td >
<select class="select" name="dateactivation" value="<?php if (isset($_POST['dateactivation'])) echo htmlentities(trim($_POST['dateactivation'])); ?>" ><option>date</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select>
<option>Mois</option>
<option>Janvier</option>
<option>Février</option>
<option>Mars</option>
<option>Avril</option>
<option>Mai</option>
<option>Juin</option>
<option>Juillet</option>
<option>Août</option>
<option>Septembre</option>
<option>Octobre </option>
<option>Novembre</option>
<option>Decembre</option>
</select>
<select>
<option>Année</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
</select> </td>
</tr>
<tr>
<td>Date installation</td>
<td >
<select class="select" name="dateinstallation" value="<?php if (isset($_POST['dateinstallation'])) echo htmlentities(trim($_POST['dateinstallation'])); ?>" ><option>date</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select>
<option>Mois</option>
<option>Janvier</option>
<option>Février</option>
<option>Mars</option>
<option>Avril</option>
<option>Mai</option>
<option>Juin</option>
<option>Juillet</option>
<option>Août</option>
<option>Septembre</option>
<option>Octobre </option>
<option>Novembre</option>
<option>Decembre</option>
</select>
<select>
<option>Année</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
</select> </td>
</tr>
<tr>
<td>Adresse</td>
<td >
<input type="text" name="adressesite" class="input_ajout_agent" value="<?php if (isset($_POST['adressesite'])) echo htmlentities(trim($_POST['adressesite'])); ?>" ></td>
</tr>
<tr>
<td>ID Client</td>
<td >
<input type="text" name="idclient" class="input_ajout_agent" value="<?php if (isset($_POST['idclient'])) echo htmlentities(trim($_POST['idclient'])); ?>" ></td>
</tr>
<tr>
<td>IP adresse</td>
<td >
<input type="text" name="adresseIP" class="input_ajout_agent" value="<?php if (isset($_POST['adresseIP'])) echo htmlentities(trim($_POST['adresseIP'])); ?>" ></td>
</tr>
<tr>
<td>IP adresse manager</td>
<td >
<input type="text" name="adresseIPmanage" class="input_ajout_agent" value="<?php if (isset($_POST['adresseIPmanage'])) echo htmlentities(trim($_POST['adresseIPmanage'])); ?>" ></td>
</tr>
<tr>
<td>E-mail</td>
<td> <input type="text" name="emailsite" class="input_ajout_agent" value="<?php if (isset($_POST['emailsite'])) echo htmlentities(trim($_POST['emailsite'])); ?>"></td>
</tr>
<tr>
<td>ID Provider</td>
<td> <input type="text" name="idprovider" class="input_ajout_agent" value="<?php if (isset($_POST['idprovider'])) echo htmlentities(trim($_POST['idprovider'])); ?>"></td>
</tr>
</table>
<table width="180" border="0" class="left">
<tr>
<td>Etat Site</td>
<td >
<select class="select2" name="idetatsite" value="<?php if (isset($_POST['idetatsite'])) echo htmlentities(trim($_POST['idetatsite'])); ?>">
<option>Désactivé</option>
<option>Activé</option>
<option>Commissioné</option>
<option>Décommissioné</option>
</select>
</tr>
<tr>
<td>Pays</td>
<td >
<select class="select2" name="idpays" value="<?php if (isset($_POST['idpays'])) echo htmlentities(trim($_POST['idpays'])); ?>" >
<option>République Démocratique du Congo</option>
<option>Congo Brazzaville</option>
<option>Angola</option>
<option>Rwanda</option>
</select>
</tr>
<tr>
<td>Matricule</td>
<td> <input type="text" class="input_ajout_agent" name="matriculeSite" value="<?php if (isset($_POST['matriculeSite'])) echo htmlentities(trim($_POST['matriculeSite'])); ?>"></td>
</tr>
<tr>
<td>Téléphone</td>
<td> <input type="text" class="input_ajout_agent" name="telephone" value="<?php if (isset($_POST['telephone'])) echo htmlentities(trim($_POST['telephone'])); ?>"></td>
</tr>
<tr>
<td>Observation</td>
<td> <textarea name="observation" rows="9" cols="25" value="<?php if (isset($_POST['observation'])) echo htmlentities(trim($_POST['observation'])); ?>" ></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Enregistrer" class="submi" value="Enregistrer" /></td>
</tr>
</table>
</form></div>
</body>
</html>
Afficher la suite
21 nov. 2011 à 11:06
21 nov. 2011 à 13:14
ALTER TABLE site DROP FOREIGN KEY fk_site_provider