par
Malalatiana » 05 janv. 2015, 19:59
ok, voila le code aprés correction!!
<?php
include ("header1.php");
?>
<?php
$hostdb = 'localhost';
$userdb = 'root';
$passdb = '';
$namedb = 'parcmfb';
try
{
$conn = new PDO("mysql:host=".$hostdb."; dbname=".$namedb."", $userdb, $passdb, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$conn->exec("SET CHARACTER SET utf8");
}
catch (PDOException $e)
{
echo 'La base de donnée n\'est pas disponible';
}
if(isset($_POST['NumRespo'],$_POST['NomRespo'],$_POST['MailRespo'],$_POST['TelRespo'],$_POST['Observation']))
{
$stmt=$conn->prepare("INSERT INTO responsable(NumRespo, NomRespo, MailRespo, TelRespo, Observation) VALUES ( ?, ?, ?, ?, ?)");
$stmt->execute(array($_POST['NumRespo'],$_POST['NomRespo'],$_POST['MailRespo'],$_POST['TelRespo'],$_POST['Observation']));
$stmt=$conn->prepare("INSERT INTO responsable(NumRespo, NomRespo, MailRespo, TelRespo, Observation) VALUES ( :NumRespo, :NomRespo, :MailRespo, :TelRespo, :Observation)");
$stmt->bindParam(':NumRespo', $NumRespo);
$stmt->bindParam(':NomRespo', $NomRespo);
$stmt->bindParam(':MailRespo', $MailRespo);
$stmt->bindParam(':TelRespo', $TelRespo);
$stmt->bindParam(':Observation', $Observation);
// $stmt->execute(array(':NumRespo' => $NumRespo, ':NomRespo' => $NomRespo, ':MailRespo' => $MailRespo, ':TelRespo' => $TelRespo, ':Observation' => $Observation));
var_dump($NumRespo);
die();
header ('Location: respo.php');
exit;
}
else
{
$req = "SELECT * FROM responsable";
$res = $conn->query($req);
print("<BR> ");
foreach ($conn->query($req) as $row)
{
print $row['NumRespo'] . "\t ";
print $row['NomRespo'] . "\t";
print $row['MailRespo'] . "\t";
print $row['TelRespo'] . "\t";
print $row['Observation'] ."<BR>";
}
print(" <BR> ");
$req = "SELECT * FROM responsable";
$res = $conn->query($req);
while ($row = $res->fetch())
{
print $row['NumRespo'] . " " . $row['NomRespo'] . " " . $row['MailRespo'] ." " . $row['TelRespo'] . " " . $row['Observation'] ."<BR>";
}
}
$conn->query("SELECT * FROM responsable");
?>
<form name="form" action="ajout1.php" method="POST" enctype="multipart/form-data" >
<fieldset>
<legend><em>Ajout d'un Responsable</em></legend>
<table align="center">
<tr>
</td>
<label for="ChampNum">Numéro Responsable:</label>
</td>
<td>
<input type="text" id="NumRespo" name="NumRespo" require/>
</td>
</tr>
<tr>
<td>
<label for="ChampNom">Nom Responsable:</label>
</td>
<td>
<input type="text" id="NomRespo" name="NomRespo" require/>
</td>
</tr>
<tr>
<td>
<label for="ChampMail">Mail Responsable:</label>
</td>
<td>
<input type="text" id="MailRespo" name="MailRespo" require/>
</td>
</tr>
<tr>
<td>
<label for="ChampTel">Téléphone Responsable:</label>
</td>
<td>
<input type="text" id="TelRespo" name="TelRespo" require/>
</td>
</tr>
<tr>
<td>
<label for="Champobs">Observation:</label>
</td>
<td>
<input type="text" id="Observation" name="Observation" require/>
</td>
</tr>
<tr>
<td></td>
<td>
<form action="ajout1.php" method="POST">
<input type="submit" name="bouton" value="Ajouter" onclick="alert('Ajout avec succes');" />
<input type="reset" name="bouton" value="Annuler" onclick="alert('Ajout annuler');" />
</form>
</td>
</tr>
</table>
</fieldset>
</form>
<?php
include ("footer.php");
?>
ok, voila le code aprés correction!!
[php]<?php
include ("header1.php");
?>
<?php
$hostdb = 'localhost';
$userdb = 'root';
$passdb = '';
$namedb = 'parcmfb';
try
{
$conn = new PDO("mysql:host=".$hostdb."; dbname=".$namedb."", $userdb, $passdb, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$conn->exec("SET CHARACTER SET utf8");
}
catch (PDOException $e)
{
echo 'La base de donnée n\'est pas disponible';
}
if(isset($_POST['NumRespo'],$_POST['NomRespo'],$_POST['MailRespo'],$_POST['TelRespo'],$_POST['Observation']))
{
$stmt=$conn->prepare("INSERT INTO responsable(NumRespo, NomRespo, MailRespo, TelRespo, Observation) VALUES ( ?, ?, ?, ?, ?)");
$stmt->execute(array($_POST['NumRespo'],$_POST['NomRespo'],$_POST['MailRespo'],$_POST['TelRespo'],$_POST['Observation']));
$stmt=$conn->prepare("INSERT INTO responsable(NumRespo, NomRespo, MailRespo, TelRespo, Observation) VALUES ( :NumRespo, :NomRespo, :MailRespo, :TelRespo, :Observation)");
$stmt->bindParam(':NumRespo', $NumRespo);
$stmt->bindParam(':NomRespo', $NomRespo);
$stmt->bindParam(':MailRespo', $MailRespo);
$stmt->bindParam(':TelRespo', $TelRespo);
$stmt->bindParam(':Observation', $Observation);
// $stmt->execute(array(':NumRespo' => $NumRespo, ':NomRespo' => $NomRespo, ':MailRespo' => $MailRespo, ':TelRespo' => $TelRespo, ':Observation' => $Observation));
var_dump($NumRespo);
die();
header ('Location: respo.php');
exit;
}
else
{
$req = "SELECT * FROM responsable";
$res = $conn->query($req);
print("<BR> ");
foreach ($conn->query($req) as $row)
{
print $row['NumRespo'] . "\t ";
print $row['NomRespo'] . "\t";
print $row['MailRespo'] . "\t";
print $row['TelRespo'] . "\t";
print $row['Observation'] ."<BR>";
}
print(" <BR> ");
$req = "SELECT * FROM responsable";
$res = $conn->query($req);
while ($row = $res->fetch())
{
print $row['NumRespo'] . " " . $row['NomRespo'] . " " . $row['MailRespo'] ." " . $row['TelRespo'] . " " . $row['Observation'] ."<BR>";
}
}
$conn->query("SELECT * FROM responsable");
?>
<form name="form" action="ajout1.php" method="POST" enctype="multipart/form-data" >
<fieldset>
<legend><em>Ajout d'un Responsable</em></legend>
<table align="center">
<tr>
</td>
<label for="ChampNum">Numéro Responsable:</label>
</td>
<td>
<input type="text" id="NumRespo" name="NumRespo" require/>
</td>
</tr>
<tr>
<td>
<label for="ChampNom">Nom Responsable:</label>
</td>
<td>
<input type="text" id="NomRespo" name="NomRespo" require/>
</td>
</tr>
<tr>
<td>
<label for="ChampMail">Mail Responsable:</label>
</td>
<td>
<input type="text" id="MailRespo" name="MailRespo" require/>
</td>
</tr>
<tr>
<td>
<label for="ChampTel">Téléphone Responsable:</label>
</td>
<td>
<input type="text" id="TelRespo" name="TelRespo" require/>
</td>
</tr>
<tr>
<td>
<label for="Champobs">Observation:</label>
</td>
<td>
<input type="text" id="Observation" name="Observation" require/>
</td>
</tr>
<tr>
<td></td>
<td>
<form action="ajout1.php" method="POST">
<input type="submit" name="bouton" value="Ajouter" onclick="alert('Ajout avec succes');" />
<input type="reset" name="bouton" value="Annuler" onclick="alert('Ajout annuler');" />
</form>
</td>
</tr>
</table>
</fieldset>
</form>
<?php
include ("footer.php");
?>
[/php]