Insertion dans la base de donée access de php

Fermé
zianehouria Messages postés 2 Date d'inscription mercredi 30 mai 2012 Statut Membre Dernière intervention 30 mai 2012 - 30 mai 2012 à 12:59
 a - 30 avril 2014 à 19:13
Bonjour,

mon probleme :comment éxecute la commande insert into utlisation la base de données access c-à-d comment inseré dans la base de données et programmé (utiliser PHP )

//*****

<!--?xml version="1.0" encoding="ISO-8859-1" standalone="no"?-->
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>ajout_classe</title>

</head>


<p> <img src="ajout_classe.png" width="900" height="130" />

<?php
function odbc_connect_custom($db)
{

// $dbdir is the location of your databases.
// The main thing to watch out for is permissions.
// The process your web server is running under must
// have read / write permissions to this folder

$dbdir = "C:\wamp\www\mdb\\";

$cfg_dsn = "DRIVER=Microsoft Access Driver (*.mdb);
DBQ=".$dbdir.$db.".mdb;UserCommitSync=Yes;
Threads=3;
SafeTransactions=0;
PageTimeout=5;
MaxScanRows=8;
MaxBufferSize=2048;
DriverId=281;
DefaultDir=C:/ProgramFiles/CommonFiles/ODBC/DataSources";

// The DefaultDir setting will probably be ok if you have gone for
// a typical installation

$cfg_dsn_login = "";
$cfg_dsn_mdp = "mouchawarate";

return odbc_connect($cfg_dsn,$cfg_dsn_login,$cfg_dsn_mdp);
}

function odbc_fetch_array_custom($id_res)
{

// Clear our return variable

unset($ar);

// Get the number of fields in the returned result

$colnum = odbc_num_fields($id_res);

// Fill an array with the column headers
// We do this here to save API calls.

for($i=1; $i<=$colnum;$i++)$field_name[$i]=odbc_field_name($id_res,$i);

// If we have a result

if (odbc_fetch_row($id_res))
{

// Fill our return array with the column data

for ($i = 1; $i <= $colnum; $i++)
$ar[$field_name[$i]] = odbc_result($id_res, $field_name[$i]);

return $ar;
}
else
{
return false;
}
}

?>
<?php
session_start();
$db = "t"; // ici mettez le nom de la base de données ...
$connection_id = odbc_connect_custom($db)or die ("Impossible de se connecter à la bas de donnée") ;
//Heure début :
$heured ='';
if (isset($_POST [" heured "])) {
$heured = $_POST [" heured "];}
//Heure fin :
$heuref ='';
if (isset($_POST [" heuref "])) {
$heuref = $_POST [" heuref "];}
//Promotion:
$promotion ='';
if (isset($_POST [" promotion "])) {
$promotion = $_POST [" promotion "];}

//Nom classe:
$nomcl ='';
if (isset($_POST [" nomcl "])) {
$nomcl = $_POST[" nomcl "];}
//Enseignant :
$NomEnse ='';
if (isset($_POST [" NomEnse "])) {
$NomEnse = $_POST [" NomEnse "];}
//group:
$group ='';
if (isset($_POST [" group "])) {
$group = $_POST [" group "];}
//matiere :
$mati='';
if (isset($_POST [" mati "])) {
$mati = $_POST [" mati "];}
//type Cours :
$Cours ='';
if (isset($_POST ["Cours "])) {
$Cours = $_POST [" Cours "];}
//Jour:
$Jour ='';
if (isset($_POST ["Jour "])) {
$Jour = $_POST [" Jour "];}

//odbc_do("insert into Affectations (Réf_Enseignant,Réf_Emplacement, TxtHD, TxtHF,Jour, Réf_Group, AnnéeCycle, type_Cours) values ('$NomEnse','$nomcl','$heured','$heuref','$Jour','$group','$promotion','$Cours')");
$sqll=("insert into Affectations (Réf_Enseignant,Réf_Cours,Réf_Emplacement,Heure_Début ,TxtHD,Heure_Fin, TxtHF,Jour, Réf_Section, Réf_Group, AnnéeCycle, type_Cours,délai1,délai2,délai3,délai4) values ('40','10','11:00','12:30','Lundi', '1', '0','1LMImi','C','0','0','0','0')");
$requete= odbc_exec($connection_id,$sqll) or die( "impossible" ) ;

//affichage des résultats, pour savoir si l'insertion a marchée:
if($requete){
echo("<center>L'insertion a été correctement effectuée</center>") ;
}else
echo("<center>L'insertion à échouée</center>") ;

?>
<form action="ajout_siense.php" method="POST">
Nom classe : <select name="nomcl">
<?php
$query="SELECT DISTINCT Réf_Emplacement FROM Affectations " ;

$result_id = odbc_exec($connection_id,$query);

while($result=odbc_fetch_array($result_id ))
{ echo '<option value="'.$i.'">'.$result['Réf_Emplacement'].'</option>'; }

?></select><br/><br/>
Promotion : <select name="promotion">
<?php
$query="SELECT DISTINCT AnnéeCycle FROM Affectations ";

$result_id = odbc_exec($connection_id,$query);

while($result=odbc_fetch_array($result_id ))
{ echo '<option value="'.$i.'">'.$result['AnnéeCycle'].'</option>'; }

?></select><br/><br/>
group : <input type="text" name="group"><br/><br/>

matiere : <select name="mati">
<?php
$query="SELECT DISTINCT Cours FROM Affectations ,Cours WHERE Cours.Réf_Cours=Affectations.Réf_Cours" ;

$result_id = odbc_exec($connection_id,$query);

while($result=odbc_fetch_array($result_id ))
{ echo '<option value="'.$i.'">'.$result['Cours'].'</option>'; }

?></select><br/><br/>
type siense : <select name="Cours">

<?php
$query="SELECT DISTINCT type_Cours FROM Affectations " ;

$result_id = odbc_exec($connection_id,$query);

while($result=odbc_fetch_array($result_id ))
{ echo '<option value="'.$i.'">'.$result['type_Cours'].'</option>'; }

?></select><br/><br/>
Jour : <select name="Jour">
<?php
$query="SELECT DISTINCT Jour FROM Affectations " ;

$result_id = odbc_exec($connection_id,$query);

while($result=odbc_fetch_array($result_id ))
{ echo '<option value="'.$i.'">'.$result['Jour'].'</option>'; }

?></select><br/><br/>
Heure début : <select name="heured">
<?php
$query="SELECT DISTINCT TxtHD FROM Affectations " ;

$result_id = odbc_exec($connection_id,$query);

while($result=odbc_fetch_array($result_id ))
{ echo '<option value="'.$i.'">'.$result['TxtHD'].'</option>'; }

?></select><br/><br/>
Heure fin : <select name="heuref">
<?php
$query="SELECT DISTINCT TxtHF FROM Affectations " ;

$result_id = odbc_exec($connection_id,$query);

while($result=odbc_fetch_array($result_id ))
{ echo '<option value="'.$i.'">'.$result['TxtHF'].'</option>'; }

?></select><br/><br/>
Enseignant : <select name="NomEnse">
<?php
$query="SELECT DISTINCT Nom_Enseignant,Enseignants.Réf_Enseignant,Affectations.Réf_Enseignant FROM Affectations ,Enseignants WHERE Enseignants.Réf_Enseignant=Affectations.Réf_Enseignant" ;

$result_id = odbc_exec($connection_id,$query);

while($result=odbc_fetch_array($result_id ))
{ echo '<option value="'.$i.'">'.$result['Nom_Enseignant'].'</option>'; }

?></select><br/><br/>

<center><input type="image" src="button.png"></center>
</form>





<br/><a href="indee.php">Revenir à la page principale !</a>
</div>
</pre></center>

</div>
</pre>
</center>
</div>
</html>

////////////////////////////////////////////////
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][Pilote ODBC Microsoft Access] Le nombre de valeurs de la requête doit coïncider avec le nombre de champs destination., SQL state 21S01 in SQLExecDirect in C:\wamp\www\index\ajout_siense.php on line 120
impossible




A voir également:

1 réponse

Utilisateur anonyme
30 mai 2012 à 14:43
Bonjour

$sqll=("insert into Affectations (Réf_Enseignant,Réf_Cours,Réf_Emplacement,Heure_Début ,TxtHD,Heure_Fin, TxtHF,Jour, Réf_Section, Réf_Group, AnnéeCycle, type_Cours,délai1,délai2,délai3,délai4) values ('40','10','11:00','12:30','Lundi', '1', '0','1LMImi','C','0','0','0','0')");

Il y a 14 champs destination, mais que 13 valeurs. Essaye de faire correspondre chacune des valeurs à chacun des champs, tu verras qu'il y a un problème.
0
$sql =" INSERT INTO [Actions](Iduser,[Date],[Action],Observation)
VALUES($IDUS,'$DD','$AA','$OB')";
0