<?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=eliate', 'root', '');
}
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 ,
sscategorie ,
accueil ,
focus ,
nom ,
ref ,
intro ,
description
prix ,
dossier
photo01 ,
photo02 ,
photo03 ,
photo04
WHERE id = '.$id.' ');
$req->execute(array(
':categorie' => $categorie,
':sscategorie' => $sscategorie,
':accueil' => $accueil,
':focus' => $focus,
':nom' => $nom,
':ref' => $ref,
':intro' => $intro,
':intro' => $description,
':prix' => $prix,
':dossier' => $dossier,
':photo01' => $photo01,
':photo02' => $photo02,
':photo03' => $photo03,
':photo04' => $photo04,
':id' => $id
));
}
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());
}
else
{
//Si tout va bien, on informe que la modification est faite
echo '
<table align="center" width="800" height="400" bgcolor="#efe8cc">
<tr>
<td align="center" valign="top">
<br><br>
<table width="600" height="400">
<tr>
<td valign="top" width="720" align="center">
<font style="color:#CC3300; font-family:Arial, Helvetica, sans-serif; font-size:24px; font-weight:bold">
VOUS AVEZ BIEN MODIFIER LE PRODUIT<br><br>
</font>
<font style="color:#CC3300; font-family:Arial, Helvetica, sans-serif; font-size:20px; font-weight:bold">
<a href=admin.php>Revenir à l\'administration.</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
';
}
//On ferme if(isset($_POST["Modifier"]))
}
?>
Quand je clique sur modifier cela m'affiche :
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(8) "modifier"
["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(2) "20"
["id"]=>
string(2) "12"
["Modifier"]=>
string(8) "Modifier"
}
voila et ca ne m'ecrit aucun mesasge d'erreur quand je valide, mais par contre le code ne modifi rien du tout $req = $bdd->prepare('UPDATE produits SET
categorie ,
sscategorie ,
accueil ,
focus ,
nom ,
ref ,
intro ,
description
prix ,
dossier
photo01 ,
photo02 ,
photo03 ,
photo04
WHERE id = '.$id.' ');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(8) "modifier"
["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(4) "modi"
["prix"]=>
string(2) "20"
["id"]=>
string(2) "12"
["Modifier"]=>
string(8) "Modifier"
}
ca veut quand meme dire que sql comprend les modifications non ?<?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=eliate', 'root', '');
}
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(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());
}
else
{
//Si tout va bien, on informe que la modification est faite
echo '
<table align="center" width="800" height="400" bgcolor="#efe8cc">
<tr>
<td align="center" valign="top">
<br><br>
<table width="600" height="400">
<tr>
<td valign="top" width="720" align="center">
<font style="color:#CC3300; font-family:Arial, Helvetica, sans-serif; font-size:24px; font-weight:bold">
VOUS AVEZ BIEN MODIFIER LE PRODUIT<br><br>
</font>
<font style="color:#CC3300; font-family:Arial, Helvetica, sans-serif; font-size:20px; font-weight:bold">
<a href=admin.php>Revenir à l\'administration.</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
';
}
//On ferme if(isset($_POST["Modifier"]))
}
?>
et ben non... je clique sur modifier , le sql me renvoi ca :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(8) "modifier"
["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(8) "modifier"
["prix"]=>
string(2) "20"
["id"]=>
string(2) "12"
["Modifier"]=>
string(8) "Modifier"
}
et rien ne se modifie encore : (UPDATE produits SET
categorie='Bijoux',
sscategorie='Bagues',
accueil='Luxe',
focus='oui',
nom='Serpentin',
ref='BagSer001',
intro='modifier',
description='modifier aussi',
prix='20$', dossier='BagSer001',
photo1='produits/BagSer001/photo1.jpg',
photo2='produits/BagSer001/photo2.jpg',
photo3='produits/BagSer001/photo3',
photoplus='produits/BagSer001/photoplus'
WHERE id= 12
et ca a bien modifier le produit
par contre tu fais des exceptions sur tes requêtes alors que les exceptions ne sont pas activées pour PDO, il faut donc l'activé sinon t'aura jamais d'erreurs
par contre tu fais des exceptions sur tes requêtes alors que les exceptions ne sont pas activées pour PDO, il faut donc l'activé sinon t'aura jamais d'erreursstealth35, je demande régulièrement aux posteurs d'être plus explicites dans leurs questions, et là j'avoue que je dois te le demander aussi dans ton affirmation parce que je ne saisis pas à quoi tu fais référence en disant que les exceptions PDO ne sont pas activées... et si moi je ne comprends pas, je me demande comment un débutant en la matière pourra faire mieux
try
{
$req = $bdd->prepare('UPDATE produits SET
categorie =:nvcategorie ,
sscategorie =:nvsscategorie,
...'
));
}
catch(PdoException $e)
{
die('Erreur : '.$e->getMessage());
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
sauf que la requete ne renvoie pas d'exception si le mode exception n'est pas activé pour PDO, ducoup la meme si y'a une erreur dans ca requête ca va rien rendre, il faut rajouter dans ca connexion le PDO::ERRMODE_EXCEPTIONtry
{
$bdd = new PDO('mysql:host=localhost;dbname=SITE', 'ROOT', 'PASS');
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}