Insert sur deux tables

Signaler
Messages postés
20
Date d'inscription
vendredi 4 novembre 2011
Statut
Membre
Dernière intervention
18 décembre 2012
-
Bonjour tous le monde,

Mon problème est le suivant:je veux insérer des données sur des tables différents à partir d'un formulaire mais je saisie les données il me mit enregistrement rejeté voici mon de compte avec smarty


<?php
session_start();
require_once ("param.php");
/*
* Created on 28 août 10
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
require_once ("../libs/Smarty.class.php");
require_once ("../templates/Smarty.inc");
$messagesParPage = $propertie->getValue('messagesParPage');

function getCount($mysql_ressource) {
//Une connexion SQL doit être ouverte avant cette ligne...
$retour_total = mysql_query('SELECT COUNT(*) AS total FROM depannage', $mysql_ressource); //Nous récupérons le contenu de la requête dans $retour_total
$donnees_total = mysql_fetch_assoc($retour_total); //On range retour sous la forme d'un tableau.
$total = $donnees_total['total']; //On récupère le total pour le placer dans la variable $total.
return $total;
}

function getPage($total, $messagesParPage) {
//Nous allons maintenant compter le nombre de pages.
$nombreDePages = ceil($total / $messagesParPage);
if (isset ($_GET['page'])) // Si la variable $_GET['page'] existe...
{
$pageActuelle = intval($_GET['page']);
if ($pageActuelle > $nombreDePages) // Si la valeur de $pageActuelle (le numéro de la page) est plus grande que $nombreDePages...
{
$pageActuelle = $nombreDePages;
}
} else {
$pageActuelle = 1;
}
return $pageActuelle;
}

function getSelectLimit($aQuery, $pageActuelle, $messagesParPage, $mysql_ressource) {
$premiereEntree = ($pageActuelle -1) * $messagesParPage; // On calcul la première entrée à lire
// La requête sql pour récupérer les messages de la page actuelle.
$retour_messages = mysql_query($aQuery . $premiereEntree . ',' . $messagesParPage . '', $mysql_ressource);
return $retour_messages;
}

function getPageCount($total, $messagesParPage) {
$pageCount = ceil($total / $messagesParPage);
return $pageCount;
}
$messageError = "";

if ($mysql_ressource = mysql_connect($propertie->getValue('hostname'), $propertie->getValue('username'), $propertie->getValue('password'))) {
if (mysql_select_db($propertie->getValue('databaseName'), $mysql_ressource)) {
$_SESSION['laPage'] = "entreDep";

if (isset ($_GET["action"])) {
if ($_GET["action"] == 'delete') {
$idDep = $_GET["idDep"];
$sQuery "DELETE FROM depannage WHERE ID_DEPANNAGE'$idDep'";
$mysql_rs = mysql_query($sQuery, $mysql_ressource);
$smarty->assign("error", "Suppresion effectuée avec success");
} else
if ($_GET["action"] == 'modifier') {
$idDep = $_GET["idDep"];
$sQuery "SELECT d.*,c.NOM FROM depannage d,clients c WHERE c.ID_CLIENT d.ID_CLIENT AND d.ID_DEPANNAGE ='$idDep' ";
$mysql_rs = mysql_query($sQuery, $mysql_ressource);
$aRecordSet = array ();
$aRow = mysql_fetch_array($mysql_rs);
$date = $aRow["DATE_DEPANNAGE"];
$idClient = $aRow["ID_CLIENT"];
$numClient = $aRow["NOM"];
$numDep = $aRow["NUM_DEPANNAGE"];

$smarty->assign("idDepannage", $idDep);
$smarty->assign("date", $date);
$smarty->assign("idClient", $idClient);
$smarty->assign("numClient", $numClient);
$smarty->assign("depannage", $numDep);

} else
if ($_GET["action"] == 'goDepannage') {
$sQuery = "SELECT MAX(ID_DEPANNAGE) AS MAXID FROM depannage ";
$req = mysql_query($sQuery, $mysql_ressource) or die('Erreur dans “' . $sQuery . '” :
' . mysql_query());

if ($aRow = mysql_fetch_array($req)) {
$maxId = $aRow['MAXID'] + 1;
} else {
$maxId = 1;
}

$numDep = 'ST' . $maxId;
$smarty->assign("depannage", $numDep);

$idClient = $_GET["idClient"];
$sQuery "SELECT * FROM clients WHERE ID_CLIENT '$idClient' ";
$mysql_rs = mysql_query($sQuery, $mysql_ressource);
$aRow = mysql_fetch_array($mysql_rs);
$numClient = $aRow["NUM_CLIENT"];
$nom = $aRow["NOM"];

$smarty->assign("idClient", $idClient);
$smarty->assign("numClient", $nom);

}
$sQuery "SELECT d.*,c.NOM FROM depannage d,clients c WHERE c.ID_CLIENT d.ID_CLIENT ORDER BY d.ID_DEPANNAGE DESC LIMIT ";
$total = getCount($mysql_ressource);
$pageActuelle = getPage($total, $messagesParPage);
$pageCount = getPageCount($total, $messagesParPage);
//$mysql_rs = mysql_query($sQuery, $mysql_ressource);
$mysql_rs = getSelectLimit($sQuery, $pageActuelle, $messagesParPage, $mysql_ressource);
//$retour_message = mysql_query($sQuery, $mysql_ressource);
$aRecordSetPro = array ();
while ($donnees_messages = mysql_fetch_assoc($mysql_rs)) {
array_push($aRecordSetPro, $donnees_messages);
}
$_SESSION['pageActuelle'] = $pageActuelle;
$_SESSION['nombreDePages'] = $messagesParPage;
$_SESSION['pageCount'] = $pageCount;

$smarty->assign("smarty_table_mysql", $aRecordSetPro);
$smarty->assign("titre", "STOCK");
$smarty->assign("active", "active");
$smarty->display("entreDep.tpl");
} else {
$sQuery = "SELECT MAX(ID_DEPANNAGE) AS MAXID FROM depannage ";
$req = mysql_query($sQuery, $mysql_ressource) or die('Erreur dans “' . $sQuery . '” :
' . mysql_query());

if ($aRow = mysql_fetch_array($req)) {
$maxId = $aRow['MAXID'] + 1;
} else {
$maxId = 1;
}

$numDep = 'ST' . $maxId;
$smarty->assign("depannage", $numDep);

if (!empty ($_REQUEST['save'])) {
if (empty ($_REQUEST['idClient'])) {
$messageError = "Veuillez passer par client!!!";
$smarty->assign("error", $messageError);
} else
if (empty ($_REQUEST['type']) || empty ($_REQUEST['marque'])) {
$messageError = "Veuillez remplir es champs obligatoire (*)";
$smarty->assign("error", $messageError);
} else {
$date = $_REQUEST['date'];
$idClient = $_REQUEST['idClient'];
$numDep = $_REQUEST['depannage'];

$sQuery = "INSERT INTO depannage (`NUM_DEPANNAGE`,`DATE_DEPANNAGE`,`ID_CLIENT`) VALUES('$numDep','$date','$idClient')";
$mysql_rs = mysql_query($sQuery, $mysql_ressource);

//$idDep = mysql_insert_id();
//$parcours = 0;
$type = $_REQUEST['type'];
$marque = $_REQUEST['marque'];
$model = $_REQUEST['model'];
$serie = $_REQUEST['serie'];
$frais = $_REQUEST['frais'];
$info = $_REQUEST['info'];
$panned = $_REQUEST['panned'];
$panne = $_REQUEST['panne'];
$travaux = $_REQUEST['travaux'];
$intervenant = $_REQUEST['intervenant'];
$conseils = $_REQUEST['conseils'];
/*
$type = array ();
while (list ($num, $val) = each($_REQUEST['type'])) {
$type[] = $val;
}

$marque = array ();
while (list ($num, $val) = each($_REQUEST['marque'])) {
$marque[] = $val;

}
$model = array ();
while (list ($num, $val) = each($_REQUEST['model'])) {
$model[] = $val;
}
$serie = array ();
while (list ($num, $val) = each($_REQUEST['serie'])) {
$serie[] = $val;
}
$frais = array ();
while (list ($num, $val) = each($_REQUEST['frais'])) {
$frais[] = $val;
}

$info = array ();
while (list ($num, $val) = each($_REQUEST['info'])) {
$info[] = $val;
}*/

//for ($index = 1; $index < count($type); $index++) {

$sQuery = "INSERT INTO mamachine (ID_DEPANNAGE,TYPE,MARQUE,MODEL,SERIE,FRAIS,INFO,PANNE_DECLARE,PANNE_DECTETE,TRAVAUX_EFFECTUES,INTERVENANT,CONSEILS) values('$idDep','$type','$marque','$model','$serie','$frais','$info','$panned','$panne','$travaux','$intervenant','$conseils')";
$mysql_rs = mysql_query($sQuery, $mysql_ressource);

//}

if ($mysql_rs) {
$messageError = "Enregistrement effectué avec succes ";
} else {
$messageError = "Enregistrement rejetée ";

}

}
$sQuery "SELECT d.*,c.NOM FROM depannage d,clients c WHERE c.ID_CLIENT d.ID_CLIENT ORDER BY d.ID_DEPANNAGE DESC LIMIT ";
} else
if (!empty ($_REQUEST['modifier'])) {
if (empty ($_REQUEST['type']) || empty ($_REQUEST['marque'])) {
$messageError = "Veuillez saisir la désignation";
} else {
$date = $_REQUEST['date'];
$idDep = $_REQUEST['idDepannage'];
$idClient = $_REQUEST['idClient'];

$sQuery = "UPDATE depannage SET DATE_DEPANNAGE='$date' WHERE ID_DEPANNAGE='$idDep'";
$mysql_rs = mysql_query($sQuery, $mysql_ressource);
$messageError = "Modification effectuer avec succes";
}
$sQuery "SELECT d.*,c.NOM FROM depannage d,clients c WHERE c.ID_CLIENT d.ID_CLIENT ORDER BY d.ID_DEPANNAGE DESC LIMIT ";
} else
if (!empty ($_REQUEST['rechercher'])) {
$clauseWhere = "";
if (!empty ($_REQUEST['depannage'])) {
$critariat = $_REQUEST['depannage'];
$clauseWhere $clauseWhere . " AND NUM_DEPANNAGE'$critariat'";
}
if (!empty ($_REQUEST['numClient'])) {
$critariat = $_REQUEST['numClient'];
$clauseWhere = $clauseWhere . " AND c.NOM LIKE'%$critariat%'";
}

$sQuery "SELECT d.*,c.NOM FROM depannage d,clients c " . preg_replace('/AND/', 'WHERE', $clauseWhere, 1) . "AND c.ID_CLIENT d.ID_CLIENT ORDER BY ID_DEPANNAGE DESC LIMIT ";

} else {
$sQuery "SELECT d.*,c.NOM FROM depannage d,clients c WHERE c.ID_CLIENT d.ID_CLIENT ORDER BY d.ID_DEPANNAGE DESC LIMIT ";
}

$total = getCount($mysql_ressource);
$pageActuelle = getPage($total, $messagesParPage);
$pageCount = getPageCount($total, $messagesParPage);
$mysql_rs = getSelectLimit($sQuery, $pageActuelle, $messagesParPage, $mysql_ressource);
//dja declarer en haut
$aRecordSetarticle = array ();
while ($aRow = mysql_fetch_array($mysql_rs)) {
array_push($aRecordSetarticle, $aRow);
}
$_SESSION['pageActuelle'] = $pageActuelle;
$_SESSION['pageCount'] = $pageCount;

$sQuery = "SELECT MAX(ID_DEPANNAGE) AS MAXID FROM depannage ";
$req = mysql_query($sQuery, $mysql_ressource) or die('Erreur dans “' . $sQuery . '” :
' . mysql_query());

if ($aRow = mysql_fetch_array($req)) {
$maxId = $aRow['MAXID'] + 1;
} else {
$maxId = 1;
}

$numDep = 'ST' . $maxId;
$smarty->assign("depannage", $numDep);

$smarty->assign("smarty_table_mysql", $aRecordSetarticle);
$smarty->assign("message", $messageError);
$smarty->assign("titre", "CLIENT");
$smarty->assign("active", "active");
$smarty->display("entreDep.tpl");
mysql_close($mysql_ressource);

}
} else {
$messageError = "connexion à la base acg impossible";
$smarty->assign("error", $messageError);
$smarty->assign("titre ", "ERROR");
$smarty->assign(" active ", " active ");
$smarty->display("error.tpl");
}
} else {
$messageError = "connexion au serveur localhost impossible";
$smarty->assign("error", $messageError);
$smarty->assign("titre", "ERROR");
$smarty->assign(" active ", "active");
$smarty->display("error.tpl");
}
?>

merci d'avance