8722 sujets

Développement web côté serveur, CMS

Bonjour à tous et à toutes,

Je suis actuellement sur la conception d'un système permettant à un membre la modification d'une de ses publications précédentes.

Lorsque je souhaite modifier une publication sous le membre "x" pour y modifier par exemple juste le Titre,
et que je valide la modification, ( sans avoir changé l'image ) elle est remplacé par une image vide ^^'.

Faut-il créer une requête séparé pour l'image ? voici mon code :

if (isset($_POST['sent'])) 
{
	$titreoeuvre=$_POST['titre_oeuvre'];
 $descriptionoeuvre=$_POST['description_oeuvre'];
 $categorie=$_POST['oeuvre_categorie'];
 $style=$_POST['oeuvre_style'];
 $date_crea=$_POST['date_crea'];
	if ($_FILES['image_oeuvre']['name']!=NULL)
	{
 $imageoeuvre=$_FILES['image_oeuvre']['name'];
 $ext = strtolower(pathinfo($imageoeuvre,PATHINFO_EXTENSION));
$allow_ext = array('jpg','png','gif','bmp','jpeg');
if (!empty($imageoeuvre))
{
if (in_array($ext,$allow_ext))
{
	$destination ="./images/oeuvres/".$imageoeuvre;
move_uploaded_file($_FILES['image_oeuvre']['tmp_name'],$destination);

}
else
{
	echo '<p class="texteerror">'."Votre fichier contient une mauvaise extension, ou n'est pas une image.".'</p>';
}
}
	}
 
 if ( (!empty($imageoeuvre)) OR (!empty($titreoeuvre)) OR (!empty($descriptionoeuvre)) OR (!empty($categorie)) OR (!empty($style)) OR (!empty($datecreaoeuvre)) )
 
{
	try {
		$artiste_id=$_SESSION['membre_id'];
	$query2 = $bdd->prepare('UPDATE oeuvre_artiste SET oeuvre_id=:oeuvre_id, image_oeuvre=:image_oeuvre, titre_oeuvre=:titre_oeuvre, description_oeuvre=:description_oeuvre, oeuvre_categorie=:oeuvre_categorie, oeuvre_style=:oeuvre_style, date_crea=:date_crea WHERE oeuvre_id=:oeuvre_id AND artiste_id=:artiste_id');
	$query2->bindValue(':artiste_id', $artiste_id, PDO: [langue]ARAM_INT);
	$query2->bindValue(':oeuvre_id', $oeuvre_id, PDO: [langue]ARAM_INT);
	$query2->bindValue(':image_oeuvre', $imageoeuvre, PDO: [langue]ARAM_STR);
	$query2->bindValue(':titre_oeuvre', $titreoeuvre, PDO: [langue]ARAM_STR);
	$query2->bindValue(':description_oeuvre', $descriptionoeuvre, PDO: [langue]ARAM_STR);
	$query2->bindValue(':oeuvre_categorie', $categorie, PDO: [langue]ARAM_STR);
	$query2->bindValue(':oeuvre_style', $style, PDO: [langue]ARAM_STR);
	$query2->bindValue(':date_crea', $date_crea, PDO: [langue]ARAM_INT);
	$query2->execute();
	}
catch (Exception $e)
{
        echo 'Erreur : ' . $e->getMessage();
}
	echo '<p class="textevalide">'."Votre modification à bien été effectué !".'</p>';
}
}	
		$query->CloseCursor();




Merci de votre attention et votre aide.
Modifié par Reverb (09 Dec 2013 - 18:03)
Salut,

alors tout d'abord je vois des variables sans valeurs, je suppose que tout ton script n'est pas là?$oeuvre_id par exemple n'existe pas mais tu l'utilises dans ta requête d'update.
Aussi, est-ce le move_uploaded_file qui plante ou bien la requête, voir les deux?
Peux tu débugguer pas à pas, regarde le contenu de tes variables, affiche ta requête, etc ... ce genre de chose.
Salut à toi floreo et merci pour ton attention Smiley smile ,

Concernant $oeuvre_id, est définit un peu plus haut dans mon code que je n'ai pas afficher ci dessus sinon le code aurait été beaucoup trop long avec le formulaire x),
qui correspond a un get récupérant l'id d'une image sélectionné.

J'ai réussi à finir ce système, j'ai donc opté pour l'utilisation d'une requête séparé de la requête générale, et cela fonctionne parfaitement Smiley smile ,

voici mon code :

if (isset($_POST['sent'])) 
{
	$titreoeuvre=$_POST['titre_oeuvre'];
 $descriptionoeuvre=$_POST['description_oeuvre'];
 $categorie=$_POST['oeuvre_categorie'];
 $style=$_POST['oeuvre_style'];
 $date_crea=$_POST['date_crea'];
	if ($_FILES['image_oeuvre']['name']!=NULL)
	{
	$imageoeuvre=$_FILES['image_oeuvre']['name'];
 $ext = strtolower(pathinfo($imageoeuvre,PATHINFO_EXTENSION));
$allow_ext = array('jpg','png','gif','bmp','jpeg');
if (!empty($imageoeuvre))
{
if (in_array($ext,$allow_ext))
{
	$destination ="./images/oeuvres/".$imageoeuvre;
move_uploaded_file($_FILES['image_oeuvre']['tmp_name'],$destination);
$artiste_id=$_SESSION['membre_id'];
$req = $bdd->prepare('UPDATE oeuvre_artiste SET image_oeuvre=:image_oeuvre WHERE artiste_id=:artiste_id AND oeuvre_id=:oeuvre_id');
$req->bindValue(':image_oeuvre', $imageoeuvre, PDO: [langue]ARAM_STR);
$req->bindValue(':artiste_id', $artiste_id, PDO: [langue]ARAM_INT);
$req->bindValue(':oeuvre_id', $oeuvre_id, PDO: [langue]ARAM_INT);
$req->execute();
}
else
{
	echo '<p class="texteerror">'."Votre fichier contient une mauvaise extension, ou n'est pas une image.".'</p>';
}
}
else
{
	$imageoeuvre = '';
}
	}
 
 if ( (!empty($imageoeuvre)) OR (!empty($titreoeuvre)) OR (!empty($descriptionoeuvre)) OR (!empty($categorie)) OR (!empty($style)) OR (!empty($datecreaoeuvre)) )
 
{
	try {
		$artiste_id=$_SESSION['membre_id'];
	$query2 = $bdd->prepare('UPDATE oeuvre_artiste SET artiste_id=:artiste_id, oeuvre_id=:oeuvre_id, titre_oeuvre=:titre_oeuvre, description_oeuvre=:description_oeuvre, oeuvre_categorie=:oeuvre_categorie, oeuvre_style=:oeuvre_style, date_crea=:date_crea WHERE oeuvre_id=:oeuvre_id AND artiste_id=:artiste_id');
	$query2->bindValue(':artiste_id', $artiste_id, PDO: [langue]ARAM_INT);
	$query2->bindValue(':oeuvre_id', $oeuvre_id, PDO: [langue]ARAM_INT);
	$query2->bindValue(':titre_oeuvre', $titreoeuvre, PDO: [langue]ARAM_STR);
	$query2->bindValue(':description_oeuvre', $descriptionoeuvre, PDO: [langue]ARAM_STR);
	$query2->bindValue(':oeuvre_categorie', $categorie, PDO: [langue]ARAM_STR);
	$query2->bindValue(':oeuvre_style', $style, PDO: [langue]ARAM_STR);
	$query2->bindValue(':date_crea', $date_crea, PDO: [langue]ARAM_INT);
	$query2->execute();
	}
catch (Exception $e)
{
        echo 'Erreur : ' . $e->getMessage();
}
	echo '<p class="textevalide">'."Votre modification à bien été effectué !".'</p>';      

}
if (isset($_POST['delete'])) {
			$artiste_id=($_SESSION['membre_id']);
            $quer = $bdd->prepare('UPDATE oeuvre_artiste SET image_oeuvre=0 WHERE artiste_id=:artiste_id AND oeuvre_id=:oeuvre_id');
            $quer->bindValue(':artiste_id', $artiste_id, PDO: [langue]ARAM_INT);
			$quer->bindValue(':oeuvre_id', $oeuvre_id, PDO: [langue]ARAM_INT);
            $quer->execute();
            $quer->CloseCursor();
        }
}	
		$query->CloseCursor();


Merci tout de même pour ton attention =),
Sincèrement.