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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| [
// Ajouter un articles
function addArticle($champs){
if(isset($champs['envoyer'])&& !empty($champs['envoyer']) && empty($champs['id']) ){
array_pop($champs);
$sql = "INSERT INTO $this->table (";
foreach ($champs as $key => $value){
$sql.=$key.',';
}
$sql = substr($sql, 0, -1);
$sql.=") VALUES(";
foreach ($champs as $key => $value){
$sql.="'".addslashes($value)."',";
}
$sql = substr($sql, 0, -1);
echo $sql.=")";
mysql_query($sql);
header("location:admin.php");
}
elseif (isset($champs['envoyer'])&& !empty($champs['envoyer']) && !empty($champs['id']) ){
array_pop($champs);
$sql = "UPDATE $this->table SET ";
foreach ($champs as $key => $value){
$sql.=$key."='".addslashes($value)."',";
}
$sql = substr($sql, 0, -1);
$sql.=" WHERE id='$champs[id]'";
mysql_query($sql);
header("location:admin.php");
}
}
<form action="" method="post" role="form" enctype="multipart/form-data" >
<div class="form-group">
<input type="hidden" name="id" value="<?php if(isset($article['id'])) {echo $article['id'];} ?>" />
<p>
<label>Titre de l'article</label>
<input type="text" name="title" value="<?php if(isset($article['title'])) {echo $article['title'];} ?>" class="form-control" placeholder="Enter le titre">
</p>
<p>
<label>Sous l'article</label>
<input type="text" name="sous" value="<?php if(isset($article['sous'])) {echo $article['sous'];} ?>" class="form-control" placeholder="Enter le sous titre">
</p>
<p>
<label>Résume de l'article</label>
<input type="text" name="resume" value="<?php if(isset($article['resume'])) {echo $article['resume'];} ?>" class="form-control" placeholder="Enter le resume">
</p>
</div>
<p>
<label>Photo</label>
<input type="file" name="photo" id="photo" />
</p>
<button type="submit" name="envoyer" value="Ajouter" class="btn btn-success">Ajouter L'article</button>
</p>
<?php $auth->addArticle($_POST); ?>
</form> |
Partager