Code : Tout sélectionner
error_reporting(E_ALL | E_STRICT);
if(isset($_POST["Modifier"]))
{
var_dump($_POST);
try
{
$bdd = new PDO('mysql:host=localhost;dbname=BDD', 'USER', 'PASS');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$id=$_POST['id'];
$categorie=$_POST['categorie'];
$sscategorie=$_POST['sscategorie'];
$accueil=$_POST['accueil'];
$focus=$_POST['focus'];
$nom=$_POST['nom'];
$ref=$_POST['ref'];
$intro=$_POST['intro'];
$description=$_POST['description'];
$prix=$_POST['prix'];
$dossier=$_POST['dossier'];
$photo01 = $_POST['photo01'];
$photo02 = $_POST['photo02'];
$photo03 = $_POST['photo03'];
$photo04 = $_POST['photo04'];
$req = $bdd->prepare('UPDATE produits SET categorie = :nvcategorie, sscategorie = :nvsscategorie, accueil = :nvaccueil, focus = :nvfocus, nom = :nvnom, ref = :nvref, intro = :nvintro, description = :nvdescription, prix = :nvprix, dossier = :nvdossier, photo01 = :nvphoto01, photo02 = :nvphoto02, photo03 = :nvphoto03, photo04 = :nvphoto04 WHERE id = :nvid ');
$req->execute(array(
'nvcategorie' => $categorie,
'nvsscategorie' => $sscategorie,
'nvaccueil' => $accueil,
'nvfocus' => $focus,
'nvnom' => $nom,
'nvref' => $ref,
'nvintro' => $intro,
'nvdescription' => $description,
'nvprix' => $prix,
'nvdossier' => $dossier,
'nvphoto01' => $photo01,
'nvphoto02' => $photo02,
'nvphoto03' => $photo03,
'nvphoto04' => $photo04,
'nvid' => $id
));
Code : Tout sélectionner
, utilise donc le bouton [PHP] pour afficher ton code s'il te plait.array(17) { ["categorie"]=> string(4) "Geek" ["nom"]=> string(6) "test06" ["sscategorie"]=> string(6) "Bagues" ["accueil"]=> string(10) "Fantaisies" ["focus"]=> string(3) "Oui" ["ref"]=> string(6) "test06" ["intro"]=> string(3) "www" ["dossier"]=> string(6) "test06" ["MAX_FILE_SIZE"]=> string(8) "10485760" ["photo01"]=> string(27) "produits/test06/photo01.jpg" ["photo02"]=> string(23) "produits/test06/photo02" ["photo03"]=> string(23) "produits/test06/photo03" ["photo04"]=> string(23) "produits/test06/photo04" ["description"]=> string(3) "eee" ["prix"]=> string(2) "50" ["id"]=> string(2) "46" ["Modifier"]=> string(8) "Modifier" }
j'ai mis comme ca le code :
<?php
error_reporting(E_ALL | E_STRICT);
if(isset($_POST["Modifier"]))
{
var_dump($_POST);
try
{
$bdd = new PDO('mysql:host=localhost;dbname=BDD', 'USER', 'PASS');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$id=$_POST['id'];
$categorie=$_POST['categorie'];
$sscategorie=$_POST['sscategorie'];
$accueil=$_POST['accueil'];
$focus=$_POST['focus'];
$nom=$_POST['nom'];
$ref=$_POST['ref'];
$intro=$_POST['intro'];
$description=$_POST['description'];
$prix=$_POST['prix'];
$dossier=$_POST['dossier'];
$photo01 = $_POST['photo01'];
$photo02 = $_POST['photo02'];
$photo03 = $_POST['photo03'];
$photo04 = $_POST['photo04'];
try
{
$req = $bdd->prepare('UPDATE produits SET categorie = :nvcategorie, sscategorie = :nvsscategorie, accueil = :nvaccueil, focus = :nvfocus, nom = :nvnom, ref = :nvref, intro = :nvintro, description = :nvdescription, prix = :nvprix, dossier = :nvdossier, photo01 = :nvphoto01, photo02 = :nvphoto02, photo03 = :nvphoto03, photo04 = :nvphoto04 WHERE id = :nvid ');
$req->execute(array(
'nvcategorie' => $categorie,
'nvsscategorie' => $sscategorie,
'nvaccueil' => $accueil,
'nvfocus' => $focus,
'nvnom' => $nom,
'nvref' => $ref,
'nvintro' => $intro,
'nvdescription' => $description,
'nvprix' => $prix,
'nvdossier' => $dossier,
'nvphoto01' => $photo01,
'nvphoto02' => $photo02,
'nvphoto03' => $photo03,
'nvphoto04' => $photo04,
'nvid' => $id
));
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$dossier = $_POST['dossier'];
$photo01 = $_POST['photo01'];
$photo02 = $_POST['photo02'];
$photo03 = $_POST['photo03'];
$photo04 = $_POST['photo04'];
$destination = "../produits/";
function upload($index,$destination,$maxsize=FALSE,$extensions=FALSE)
{
//Test1: fichier correctement uploadé
if (!isset($_FILES[$index]) OR $_FILES[$index]['error'] > 0) return FALSE;
//Test2: taille limite
if ($maxsize !== FALSE AND $_FILES[$index]['size'] > $maxsize) return FALSE;
//Test3: extension
$ext = substr(strrchr($_FILES[$index]['name'],'.'),1);
if ($extensions !== FALSE AND !in_array($ext,$extensions)) return FALSE;
//Déplacement
return move_uploaded_file($_FILES[$index]['tmp_name'],$destination);
}
//EXEMPLES
chmod("../produits/$dossier", 0777);
$upload1 = upload("photo1","../$photo01",10485760, FALSE );
$upload2 = upload("photo2","../$photo02",10485760, FALSE );
$upload3 = upload("photo3","../$photo03",10485760, FALSE );
$upload4 = upload("photoplus","../$photo04",10485760, FALSE );
if (!$bdd)
{
die('Requête invalide : ' . mysql_error());
}
else
{
echo '
bon desole pour le desordre mais c est seulement la 2eme fois que j ecris dans un forum pour de l aide, et la vraiment je ne comprends pas pourquoi la modification ne se fait pas, car j avais utilise deja ce code avant ( enfin sans requete preparee ) et la modification se faisait sans probleme.<?php
error_reporting(E_ALL | E_STRICT);
function upload($index,$destination,$maxsize=FALSE,$extensions=FALSE)
{
//Test1: fichier correctement uploadé
if (!isset($_FILES[$index]) || $_FILES[$index]['error'] > 0)
{
return FALSE;
}
//Test2: taille limite
if ($maxsize !== FALSE && $_FILES[$index]['size'] > $maxsize)
{
return FALSE;
}
//Test3: extension
$ext = substr(strrchr($_FILES[$index]['name'],'.'),1);
if ($extensions !== FALSE && !in_array($ext,$extensions))
{
return FALSE;
}
//Déplacement
return move_uploaded_file($_FILES[$index]['tmp_name'],$destination);
}
if(isset($_POST["Modifier"]))
{
echo("<pre>\n");
var_dump($_POST);
echo("</pre>\n");
try
{
$bdd = new PDO('mysql:host=localhost;dbname=BDD', 'USER', 'PASS');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$id = $_POST['id'];
$categorie = $_POST['categorie'];
$sscategorie = $_POST['sscategorie'];
$accueil = $_POST['accueil'];
$focus = $_POST['focus'];
$nom = $_POST['nom'];
$ref = $_POST['ref'];
$intro = $_POST['intro'];
$description = $_POST['description'];
$prix = $_POST['prix'];
$dossier = $_POST['dossier'];
$photo01 = $_POST['photo01'];
$photo02 = $_POST['photo02'];
$photo03 = $_POST['photo03'];
$photo04 = $_POST['photo04'];
try
{
$sql = 'UPDATE produits SET '.
' categorie = :nvcategorie, '.
' sscategorie = :nvsscategorie, '.
' accueil = :nvaccueil, '.
' focus = :nvfocus, '.
' nom = :nvnom, '.
' ref = :nvref, '.
' intro = :nvintro, '.
' description = :nvdescription, '.
' prix = :nvprix, '.
' dossier = :nvdossier, '.
' photo01 = :nvphoto01, '.
' photo02 = :nvphoto02, '.
' photo03 = :nvphoto03, '.
' photo04 = :nvphoto04 '.
'WHERE id = :nvid ';
$req = $bdd->prepare($sql);
$parametres = array(
':nvcategorie' => $categorie,
':nvsscategorie' => $sscategorie,
':nvaccueil' => $accueil,
':nvfocus' => $focus,
':nvnom' => $nom,
':nvref' => $ref,
':nvintro' => $intro,
':nvdescription' => $description,
':nvprix' => $prix,
':nvdossier' => $dossier,
':nvphoto01' => $photo01,
':nvphoto02' => $photo02,
':nvphoto03' => $photo03,
':nvphoto04' => $photo04,
':nvid' => $id
);
$bdd->execute($parametres);
}
catch(PdoException $e)
{
die('Erreur : '.$e->getMessage());
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$destination = "../produits/";
//EXEMPLES
chmod("../produits/$dossier", 0777);
$upload1 = upload("photo1", "../$photo01", 10485760, FALSE );
$upload2 = upload("photo2", "../$photo02", 10485760, FALSE );
$upload3 = upload("photo3", "../$photo03", 10485760, FALSE );
$upload4 = upload("photoplus", "../$photo04", 10485760, FALSE );
if (!$bdd)
{
die('Requête invalide : ' . mysql_error());
}
//... et la suite...?
Corrige sur cette base et note la correction dans ton tableau de paramètres envoyé pour l'exécution de requêtes.else
{
echo '
<font style="color:#CC3300; font-family:Arial, Helvetica, sans-serif; font-size:24px; font-weight:bold">
VOUS AVEZ BIEN MODIFIER LE PRODUIT</font>
';
}
/On ferme if(isset($_POST["Modifier"]))
}
?>
voila je suis entrain de voir ce que tu m as envoye//On ferme if(isset($_POST["Modifier"]))
}
?>
et j'essai de voir ou est le probleme je ne vois pas...array(17) {
["categorie"]=>
string(6) "Bijoux"
["nom"]=>
string(9) "Serpentin"
["sscategorie"]=>
string(6) "Bagues"
["accueil"]=>
string(4) "Luxe"
["focus"]=>
string(3) "Oui"
["ref"]=>
string(9) "BagSer001"
["intro"]=>
string(26) "Tres belle bagues Or Blanc"
["dossier"]=>
string(9) "BagSer001"
["MAX_FILE_SIZE"]=>
string(8) "10485760"
["photo01"]=>
string(29) "produits/BagSer001/photo1.jpg"
["photo02"]=>
string(29) "produits/BagSer001/photo2.jpg"
["photo03"]=>
string(25) "produits/BagSer001/photo3"
["photo04"]=>
string(28) "produits/BagSer001/photoplus"
["description"]=>
string(39) " Or blanc
Crystal Swarovski
"
["prix"]=>
string(3) "10$"
["id"]=>
string(2) "12"
["Modifier"]=>
string(8) "Modifier"
}
Fatal error: Call to undefined method PDO::execute() in C:\wamp\www\eliateOK\adm\modifierproduitok.php on line 123 $bdd->execute($parametres);
Code : Tout sélectionner
Warning: PDO::exec() expects parameter 1 to be string, array given in C:\wamp\www\eliateOK\adm\modifierproduitok.php on line 123