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
|
<?
//variable de mon formulaire
$ent=$_POST['nom_ent'];
$prenom=$_POST['prenom_ct'];
$nom=$_POST['nom_ct'];
$fonction=$_POST['fonction_ct'];
$tel=$_POST['tel_ct'];
$mail=$_POST['mail_ct'];
//je recupere le nom de l'entreprise et fait une requete pour recuperer son ID
$result=pg_exec($conn,"SELECT id_ent FROM entreprise WHERE nom_ent='$ent';");
$rows=pg_numrows($result);
if ($result)
{
for ($i=0; $i < $rows;$i++)
{
$myarray=pg_fetch_row($result,$i);
echo ("$myarray[0]\n");
}
}
//jusque la tout va bien ;-)j'ai bien l'ID correspondant au nom de l'entreprise
$resultat=pg_exec($conn,"INSERT INTO contact(id_ct,id_ent,prenom_ct,nom_ct,fonction_ct,tel_ct,mail_ct) VALUES (NEXTVAL('contact_id_ct_seq'),'".$result[0]."','$prenom','$nom','$fonction','$tel','$mail');");
$rows2=pg_numrows($resultat);
if ($resultat)
{
for ($i=0; $i < $rows2;$i++)
{
$myarray=pg_fetch_row($rows2,$i);
echo ("array: $myarray[0] - $myarray[1]<br>- $myarray[2]<br>- $myarray[3]<br>- $myarray[4]<br>- $myarray[5]<br>\n");
}
}
else
{
printf ("ERROR");
$errormessage = pg_errormessage($db);
echo $errormessage;
exit;
}
?> |
Partager