Problème update image

mheddine Messages postés 4 Date d'inscription samedi 21 juin 2014 Statut Membre Dernière intervention 21 juillet 2014 - 21 juin 2014 à 19:41
jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 - 23 juin 2014 à 10:06
Bonjour,

j'ai un petit problème dans mon code PHP est ce quand je fait une modification dans le formulaire sans modifier l'image une ou tous les images ils disparusse quand je exécute ma requête SELECT merci bien de m'aider:


<?php

include ("../config.php");


//edit records
if (isset($_POST['edit'])) {

$id = $_POST['id'];
$categorie = mysql_real_escape_string(htmlspecialchars($_POST['categorie']));
$titrear = mysql_real_escape_string(htmlspecialchars($_POST['titrear']));
$prixe = mysql_real_escape_string(htmlspecialchars($_POST['prixe']));
$prixd = mysql_real_escape_string(htmlspecialchars($_POST['prixd']));
$description= mysql_real_escape_string(htmlspecialchars($_POST['description']));
$img1= mysql_real_escape_string(htmlspecialchars($_POST['img1']));
$img2= mysql_real_escape_string(htmlspecialchars($_POST['img2']));
$img3= mysql_real_escape_string(htmlspecialchars($_POST['img3']));
$img4= mysql_real_escape_string(htmlspecialchars($_POST['img4']));
$img5= mysql_real_escape_string(htmlspecialchars($_POST['img5']));

else{
mysql_query("update articles set categorie = '$categorie' where id = '$id'");
mysql_query("update articles set titrear = '$titrear' where id = '$id'");
mysql_query("update articles set prixe = '$prixe' where id = '$id'");
mysql_query("update articles set prixd = '$prixd' where id = '$id'");
mysql_query("update articles set description= '$description' where id = '$id'");

echo "<meta http-equiv='refresh' content='200;url=index.php' />";
echo "<div id='n_oka' align='center'><p>La mise à jour de l article à réussi<br>Vous n'avez pas changer de images</p></div>";

if (!empty($img1) OR empty($img2) OR empty($img3) OR empty($img4) OR empty($img5)){

$dir = "../../photos/";
copy($_FILES["img1"]["tmp_name"],"".$dir."".$_FILES["img1"]["name"]);
copy($_FILES["img2"]["tmp_name"],"".$dir."".$_FILES["img2"]["name"]);
copy($_FILES["img3"]["tmp_name"],"".$dir."".$_FILES["img3"]["name"]);
copy($_FILES["img4"]["tmp_name"],"".$dir."".$_FILES["img4"]["name"]);
copy($_FILES["img5"]["tmp_name"],"".$dir."".$_FILES["img5"]["name"]);

mysql_query("update articles set img1 = '$img1' where id = '$id'");
mysql_query("update articles set img2 = '$img2' where id = '$id'");
mysql_query("update articles set img3 = '$img3' where id = '$id'");
mysql_query("update articles set img4 = '$img4' where id = '$id'");
mysql_query("update articles set img5 = '$img5' where id = '$id'");

echo "<meta http-equiv='refresh' content='200;url=index.php' />";
echo "<div id='n_oka' align='center'><p>La mise à jour de l article à réussi et vous n'avez pas changer de images</p></div>";
}

}
}
?>
<form enctype="multipart/form-data" action="" method="post">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
<table>
<tr>
<td><label for="name">Categorie de l'article :</label></td>
<td>
<select name='categorie'>
<?php
$res = mysql_query("SELECT * FROM categorie order by id=".$_GET['id']."");
while($row = mysql_fetch_assoc($res)){
echo "<option value='".$row["categorie"]."'>".$row["categorie"]."</option>";
}
?>
</select>
<a href="../categorie/index.php?action=list" rel="lightbox[external 50% 350]" title="Ajouter les categories"><img src="../../images/i_add.png" style="border:none;margin:5px 0 5px 10px; position:absolute" title="Ajouter une categorie" /></a>
</td>
</tr>
<?php
$result = mysql_query("SELECT * FROM articles where id=".$_GET['id']."");
while($row = mysql_fetch_array($result)) {

?>
<tr>
<td>Titre de l'article</td>
<td><input type="text" name="titrear" value="<?php echo "$row[titrear]"; ?>" /></td>
</tr>
<tr>
<td>Prix en DT</td>
<td><input type="text" name="prixd" value="<?php echo "$row[prixd]"; ?>" /></td>
</tr>
<tr>
<td>Prix en EUR</td>
<td><input type="text" name="prixe" value="<?php echo "$row[prixe]"; ?>" /></td>
</tr>
<tr>
<td valign="top">Description : </td>
<td><textarea name="description" value="<?php echo "$row[description]"; ?>"><?php echo "$row[description]"; ?></textarea></td>
</tr>
<tr>
<td valign="top"><label for="attach">Les images :</label></td>
<td>
<input type="file" id="file" name="img1" /> <img src="../../photos/<?php echo "$row[img1]"; ?>" width="25px" height="25px" style="border:none;position:absolute;padding:5px 0 5px 10px" /><br />
<input type="file" id="file" name="img2" /> <img src="../../photos/<?php echo "$row[img2]"; ?>" width="25px" height="25px" style="border:none;position:absolute;padding:5px 0 5px 10px" /><br />
<input type="file" id="file" name="img3" /> <img src="../../photos/<?php echo "$row[img3]"; ?>" width="25px" height="25px" style="border:none;position:absolute;padding:5px 0 5px 10px" /><br />
<input type="file" id="file" name="img4" /> <img src="../../photos/<?php echo "$row[img4]"; ?>" width="25px" height="25px" style="border:none;position:absolute;padding:5px 0 5px 10px" /><br />
<input type="file" id="file" name="img5" /> <img src="../../photos/<?php echo "$row[img5]"; ?>" width="25px" height="25px" style="border:none;position:absolute;padding:5px 0 5px 10px" />
</td>
</tr>
<tr align="Right">
<td colspan="2"><label><input class="btn" type="submit" name="edit" value="Modifier" /></label></td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
}
?>

1 réponse

jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 344
23 juin 2014 à 10:04
Bonjour,

Je pense que tu as oublié des "!" dans ton if :

if (!empty($img1) OR empty($img2) OR empty($img3) OR empty($img4) OR empty($img5)){

Ne serait-ce pas plutôt :
if (!empty($img1) OR !empty($img2) OR !empty($img3) OR !empty($img4) OR !empty($img5)){

0
jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 344
23 juin 2014 à 10:06
Sachant que :
1 - Il serait préférable de traiter chaque image séparément.
2 - Une boucle foreach sur les $_FILES serait surement encore mieux.
0
Rejoignez-nous