Page 1 sur 1

Changement de donnée dans un script

Posté : 27 sept. 2011, 10:06
par philou72
Désoler pour le double post mais j'avais oublier de me connecter
bonjour a tous
J’espère que je post a la bonne place
j'ai un petit problème avec un script
je vous explique ce script dois insérer des articles dans une boutique pré-configurer (ça pas de problème )la ou je bloque c'est qu'anciennement il falait joindre un fichier .txt pour mettre la description de l'article et je voudrai pouvoir mettre le descriptif texte à insérer a la place de de ce système .
ce qui me permettrais de gagner du temps lorsque je créé un nouveau sujet
Je vous remercie d'avance pour vos réponses

J’espère avoir été clair dans l’énoncer de mon problème
Tout sélectionner
<?php
if(isset($_POST['MAX_FILE_SIZE']))
{
if($_POST) // vérifie si le tableau post existe
{
if($_POST['envoyer']) // Vérifie si le fichier a été validé
{
echo'
<div class="Body">
';
include("menu/menu_Admin.inc.php");
echo'
<div STYLE="margin-left:30px;margin-top:50px;width:300px;border:1px solid #d0d0d0;">
';
if(is_uploaded_file($_FILES['Desc_fr']['tmp_name']))
{
echo "Le fichier ".$_FILES['Desc_fr']['name']." a bien été téléchargé<br>";
echo "Il fait ".$_FILES['Desc_fr']['size']." et est de type ".$_FILES['Desc_fr']['type']."<br>";
}
else
{
echo "Le fichier ".$_FILES['Desc_fr']['name']." n'a pas été téléchargé<br>";
}
if(is_uploaded_file($_FILES['Desc_en']['tmp_name']))
{
echo "Le fichier ".$_FILES['Desc_en']['name']." a bien été téléchargé<br>";
echo "Il fait ".$_FILES['Desc_en']['size']." et est de type ".$_FILES['Desc_en']['type']."<br>";
}
else
{
echo "Le fichier ".$_FILES['Desc_en']['name']." n'a pas été téléchargé<br>";
}
if(is_uploaded_file($_FILES['ImgG']['tmp_name']))
{
echo "Le fichier ".$_FILES['ImgG']['name']." a bien été téléchargé<br>";
echo "Il fait ".$_FILES['ImgG']['size']." et est de type ".$_FILES['ImgG']['type']."<br>";
}
else
{
echo "Le fichier ".$_FILES['ImgG']['name']." n'a pas été téléchargé<br>";
}
if(is_uploaded_file($_FILES['ImgP1']['tmp_name']))
{
echo "Le fichier ".$_FILES['ImgP1']['name']." a bien été téléchargé<br>";
echo "Il fait ".$_FILES['ImgP1']['size']." et est de type ".$_FILES['ImgP1']['type']."<br>";
}
else
{
echo "Le fichier ".$_FILES['ImgP1']['name']." n'a pas été téléchargé<br>";
}
if(is_uploaded_file($_FILES['ImgP2']['tmp_name']))
{
echo "Le fichier ".$_FILES['ImgP2']['name']." a bien été téléchargé<br>";
echo "Il fait ".$_FILES['ImgP2']['size']." et est de type ".$_FILES['ImgP2']['type']."<br>";
}
else
{
echo "Le fichier ".$_FILES['ImgP2']['name']." n'a pas été téléchargé<br>";
}
if(is_uploaded_file($_FILES['ImgP3']['tmp_name']))
{
echo "Le fichier ".$_FILES['ImgP3']['name']." a bien été téléchargé<br>";
echo "Il fait ".$_FILES['ImgP3']['size']." et est de type ".$_FILES['ImgP3']['type']."<br>";
}
else
{
echo "Le fichier ".$_FILES['ImgP3']['name']." n'a pas été téléchargé<br>";
}

echo'
</div></div>
';
}
}

// ============== recherche du prochain ID_Prod ==============

include("tools/db_con.inc.php");
$sql='SELECT ID_Products FROM `tb_products`';
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$result=mysql_query($sql,$db);
$num_rows=mysql_num_rows($result);
$ID_P=$num_rows+1;

// ===========================================================

if(move_uploaded_file($_FILES['Desc_fr']['tmp_name'],"./Products/".$ID_P."/".$_FILES['Desc_fr']['name']))
{
$Desc_fr=$_FILES['Desc_fr']['name'];
$okDesc_fr="1";
}
if(move_uploaded_file($_FILES['Desc_en']['tmp_name'],"./Products/".$ID_P."/".$_FILES['Desc_en']['name']))
{
$Desc_en=$_FILES['Desc_en']['name'];
$okDesc_en="1";
}
if(move_uploaded_file($_FILES['ImgG']['tmp_name'],"./Products/".$ID_P."/".$_FILES['ImgG']['name']))
{
$ImgG=$_FILES['ImgG']['name'];
$okimgG="1";
}
if(move_uploaded_file($_FILES['ImgP1']['tmp_name'],"./Products/".$ID_P."/".$_FILES['ImgP1']['name']))
{
$ImgP1=$_FILES['ImgP1']['name'];
$okimgP1="1";
}
if(move_uploaded_file($_FILES['ImgP2']['tmp_name'],"./Products/".$ID_P."/".$_FILES['ImgP2']['name']))
{
$ImgP2=$_FILES['ImgP2']['name'];
$okimgP2="1";
}
if(move_uploaded_file($_FILES['ImgP3']['tmp_name'],"./Products/".$ID_P."/".$_FILES['ImgP3']['name']))
{
$ImgP3=$_FILES['ImgP3']['name'];
$okimgP3="1";
}

if(isset($_POST['Titre_fr']))
{
$Titre_fr=$_POST['Titre_fr'];
}
else
{
echo' Veuillez entrer le titre Français, merci!';
}
if(isset($_POST['Titre_en']))
{
$Titre_en=$_POST['Titre_en'];
}
else
{
echo' Veuillez entrer le titre Anglais, merci!';
}
if(isset($_POST['Categorie']))
{
$Categorie=$_POST['Categorie'];
}
else
{
echo' Veuillez sélectionner une catégorie, merci!';
}
if(isset($_POST['Prix']))
{
$Prix=$_POST['Prix'];
}
else
{
echo' Veuillez introduire un prix pour cet article, merci!';
}


if($okDesc_fr=="1" && $okDesc_en=="1" && $okimgG=="1" && $okimgP1=="1" && $okimgP2=="1" && $okimgP3=="1" && isset($Titre_fr) && isset($Titre_en))
{
include("tools/db_con.inc.php");
$sql='INSERT INTO `tb_products` (ID_Products,Categorie,Titre_fr,Titre_en,Description_fr,Description_en,Prix,ImgG,ImgP1,ImgP2,ImgP3) Values ("","'.$Categorie.'","'.$Titre_fr.'","'.$Titre_en.'","'.$Desc_fr.'","'.$Desc_en.'","'.$Prix.'","'.$ImgG.'","'.$ImgP1.'","'.$ImgP2.'","'.$ImgP3.'")';
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
echo " La table Produits a bien été remplie, voici les informations:";
$sql = "SELECT * FROM `tb_products` WHERE ID_Products=$ID_P" ;
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$result=mysql_query($sql,$db);
While($row=mysql_fetch_array($result))
{
echo'
<div STYLE="">
<table cellspacing="0" cellpadding="0" border="0" width="120">
<tr>
<td colspan="3">'.$row['Titre_fr'].'</td>
</tr>
<tr>
<td colspan="3">'.$row['Description_fr'].'</td>
</tr>
<tr>
<td colspan="3"><img src="Products/'.$row['ID_Products'].'/'.$row['ImgG'].'" width="120" height="90" border="0"/></td>
</tr>
<tr>
<td><img src="Products/'.$row['ID_Products'].'/'.$row['ImgP1'].'" width="40" height="30" border="0"/></td>
<td><img src="Products/'.$row['ID_Products'].'/'.$row['ImgP2'].'" width="40" height="30" border="0"/></td>
<td><img src="Products/'.$row['ID_Products'].'/'.$row['ImgP3'].'" width="40" height="30" border="0"/></td>
</tr>
<tr>
<td colspan="3">Prix : '.$row['Prix'].' €</td>
</tr>
</table>
</div>
';
}
}
else
{
echo " La table Produits n'a pas été remplie";
}
}
else
{
echo'
<div class="Body">
';
include("menu/menu_Admin.inc.php");
echo'

<br><br>
<div class="Add_News">
<table cellpadding="0" cellspacing="0" border="0" width="515">
<tr>
<td>
<div STYLE="margin-bottom:-5px;font-size:12px;">
<table cellpadding="0" cellspacing="0" border="0" width="515">
<td width="6" align="left">
<img src="pictures/Dep_tl.bmp" width="6" height="34" border="0" />
</td>
<td width="188" align="left">
<img src="pictures/Dep_t.bmp" width="300" height="34" border="0" />
</td>
<td width="19" align="left">
<img src="pictures/Dep_b_txt.bmp" width="19" height="34" border="0" />
</td>
<td width="183" STYLE="color:#fff;font-weight:bold;font-size:14px;text-align:center;background-image:url(\'pictures/Dep_txt.bmp\');background-repeat:repeat-x;">
Ajouter Produits
</td>
<td width="7" align="right">
<img src="pictures/Dep_a_txt2.bmp" width="7" height="34" border="0" />
</td>
</table>
</div>
</td>
</tr>
<tr>
<td>
<table width="515" border="0" cellpadding="0" cellspacing="0" bgcolor="#BBBBBB" align="center">
<form method="post" action="" enctype="multipart/form-data">
<tr>
<td width="500" align="center" colspan="2">&nbsp;<input type="hidden" name="MAX_FILE_SIZE" value="1024000"/></td>
</tr>
<tr>
<td width="500" align="center" colspan="2">Titres :</td>
</tr>
<tr>
<td width="150" align="right">Titre fr :&nbsp;</td><td width="350" align="left"><input type="text" name="Titre_fr" size="40"/></td>
</tr>
<tr>
<td width="150" align="right">Titre Ang :&nbsp;</td><td width="350" align="left"><input type="text" name="Titre_en" size="40"/></td>
</tr>
<tr>
<td width="500" align="center" colspan="2">Catégorie :</td>
</tr>
<tr>
<td width="150" align="right">Choix :&nbsp;</td>
<td width="350" align="left">
<select Name="Categorie">
<option value=""></option>
<option value="pcs">Ordinateurs complets</option>
<option value="portables">Portables</option>
<option value="promos">Promotions</option>
<option value="pieces">Pièces ordinateur</option>
</select>
</td>
</tr>
<tr>
<td width="500" align="center" colspan="2">Texts : (fichiers format .txt)</td>
</tr>
<tr>
<td width="150" align="right">Fichier description fr :&nbsp;</td><td width="350" align="left"><input type="file" name="Desc_fr"/></td>
</tr>
<tr>
<td width="150" align="right">Fichier description en :&nbsp;</td><td width="350" align="left"><input type="file" name="Desc_en"/></td>
</tr>
<tr>
<td width="500" align="center" colspan="2">Images : (jpg format 4:3)</td>
</tr>
<tr>
<td width="150" align="right">Fichier Grande Image :&nbsp;</td><td width="350" align="left"><input type="file" name="ImgG"/></td>
</tr>
<tr>
<td width="150" align="right">Fichier Petite Image1 :&nbsp;</td><td width="350" align="left"><input type="file" name="ImgP1"/></td>
</tr>
<tr>
<td width="150" align="right">Fichier Petite Image2 :&nbsp;</td><td width="350" align="left"><input type="file" name="ImgP2"/></td>
</tr>
<tr>
<td width="150" align="right">Fichier Petite Image3 :&nbsp;</td><td width="350" align="left"><input type="file" name="ImgP3"/></td>
</tr>
<tr>
<td width="500" align="center" colspan="2">Prix :</td>
</tr>
<tr>
<td width="150" align="right">Prix du produit :&nbsp;</td><td width="350" align="left"><input type="text" name="Prix" size="10"/>&nbsp;€</td>
</tr>
<tr>
<td colspan="2" width="500"><table width="100%"><tr><td align="right"><input class="input_btn" type="reset" value="Effacer">&nbsp;<input class="input_btn" name="envoyer" type="submit" value="Ajouter"></td></tr></table></td>
</tr>
</form>
</table>
</td>
</tr>
<tr>
<td>
<div class="rech_client_bot">
<img src="pictures/Form_bot.bmp" Width="515" Height="9"/>
</div>
</td>
</tr>
</table>
</div>
</div>
';
}

?>
et ceci est une page ou devrai etre inscrit la descritpion de l'objet
Tout sélectionner
<?php
include("tools/db_con.inc.php");
$sql = "SELECT * FROM `tb_products` WHERE Categorie='portables'" ;
   $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
   $result=mysql_query($sql,$db);
   
echo'
<div class="BodyProd">
<br/>
<div STYLE="width:300px;background:#ff0;font-size:18px;font-weight:bold;margin-left:20%;margin-right:20%;text-align:center;">
Portables
</div>
<br/><br/>
';
      While($row=mysql_fetch_array($result))
         {
         echo'
         <div STYLE="border:1px solid #bbb;width:670px;padding:5px;">
            <table cellspacing="0" cellpadding="0" border="0" width="660">
               <tr>
                  <td colspan="5" align="center"><div STYLE="font-size:14px;color:#00f;font-weight:bold;">'.$row['Titre_fr'].'&nbsp;<font color="#acacac" size="10px">[id:'.$row['ID_Products'].']</font></div></td>
               </tr>
               <tr>
                  <td colspan="3">
                     <a href="#" class="info2">
                        <img src="Products/'.$row['ID_Products'].'/'.$row['ImgG'].'" width="160" height="120" border="0"/>
                           <span>
                              <div STYLE="border:3px solid #bbbbff;width:400px;height:300px;">
                                 <table cellspacing="0" cellpadding="0" border="0">
                                    <tr>
                                       <td>
                                          <img src="Products/'.$row['ID_Products'].'/'.$row['ImgG'].'" width="400" height="300" border="0"/>
                                       </td>
                                    </tr>
                                 </table>
                              </div>
                           </span>
                     </a>
                  </td>
                  <td colspan="2" width="500">
                  <div STYLE="width:500px;padding-left:5px;padding-right:5px;font-size:14px;">';
                  //echo "Products/".$row['ID_Products']."/".$row['Description_fr'];
                  print_external_file("Products/".$row['ID_Products']."/".$row['Description_fr']);
                  echo'</div></td>
               </tr>
               <tr>
                  <td colspan="5"></td>
               </tr>
               <tr>
                  <td width="53" align="center">
                     <a href="#" class="info2">
                        <img src="Products/'.$row['ID_Products'].'/'.$row['ImgP1'].'" width="50" height="30" border="0"/>
                           <span>
                              <div STYLE="border:3px solid #bbbbff;width:400px;height:300px;">
                                 <table cellspacing="0" cellpadding="0" border="0">
                                    <tr>
                                       <td>
                                          <img src="Products/'.$row['ID_Products'].'/'.$row['ImgP1'].'" width="400" height="300" border="0"/>
                                       </td>
                                    </tr>
                                 </table>
                              </div>
                           </span>
                     </a>
                  </td>
                  <td width="53" align="center">
                     <a href="#" class="info2">
                        <img src="Products/'.$row['ID_Products'].'/'.$row['ImgP2'].'" width="50" height="30" border="0"/>
                           <span>
                              <div STYLE="border:3px solid #bbbbff;width:400px;height:300px;">
                                 <table cellspacing="0" cellpadding="0" border="0">
                                    <tr>
                                       <td>
                                          <img src="Products/'.$row['ID_Products'].'/'.$row['ImgP2'].'" width="400" height="300" border="0"/>
                                       </td>
                                    </tr>
                                 </table>
                              </div>
                           </span>
                     </a>
                  </td>
                  <td width="53" align="center">
                     <a href="#" class="info2">
                        <img src="Products/'.$row['ID_Products'].'/'.$row['ImgP3'].'" width="50" height="30" border="0"/>
                        <span>
                              <div STYLE="border:3px solid #bbbbff;width:400px;height:300px;">
                                 <table cellspacing="0" cellpadding="0" border="0">
                                    <tr>
                                       <td>
                                          <img src="Products/'.$row['ID_Products'].'/'.$row['ImgP3'].'" width="400" height="300" border="0"/>
                                       </td>
                                    </tr>
                                 </table>
                              </div>
                           </span>
                     </a>
                  </td>
                  <td width="400">
                  </td>
                  <td align="right" width="100" STYLE="background:#ff0;">
                     Prix : <b>'.$row['Prix'].' €</b>
                  </td>
               </tr>
            </table>
         </div>
         <br>
         ';
         }

echo'
</div>
';

?>

Re: Changement de donnée dans un script

Posté : 27 sept. 2011, 10:22
par macgawel
Bonjour.

Deux solutions :
- La plus simple, c'est de recopier un champ texte dans le fichier.
c'est d'avoir un champ texte pour écrire la description (en changeant le type de l'input dans le HTML).
1. Modifie le type de l'input dans le HTML.
2. Remplace le test d'upload (en début de script) par un bête test vérifiant le contenu.
3. SI le test est OK, au lieu de faire un move_uploaded_file() tu copies le contenu du champ dans le fichier.
A la lecture, tu n'as qu'à conserver le système actuel...

- La meilleure (à mon avis) c'est de rajouter des champs à ta table...
1. Modifie le type de l'input dans le HTML.
2. Remplace le test d'upload (en début de script) par un bête test vérifiant le contenu.
3. SI le test est OK, au lieu de faire un move_uploaded_file() modifie ta requête d'insertion pour rajouter les Descriptions.
A la lecture, au lieu d'utiliser la fonction maison print_external_file() tu gères comme les autres données issues de la requête SQL...

Voilà pour le principe, si tu as un problème à la mise en oeuvre n'hésite pas...

Re: Changement de donnée dans un script

Posté : 27 sept. 2011, 10:56
par philou72
je vois bien ce que tu veux dire mais je ne sais pas trop comment le mettre en oeuvre si tu peux me guider ce serai sympa

merci

Re: Changement de donnée dans un script

Posté : 27 sept. 2011, 11:27
par philou72
J'ai fait un test en changeant ceci
if(is_uploaded_file($_FILES['Desc_fr']['tmp_name']))
{
echo "Le fichier ".$_FILES['Desc_fr']['name']." a bien été téléchargé<br>";
echo "Il fait ".$_FILES['Desc_fr']['size']." et est de type ".$_FILES['Desc_fr']['type']."<br>";
}
else
{
echo "Le fichier ".$_FILES['Desc_fr']['name']." n'a pas été téléchargé<br>";
}
Par
if(isset($_POST['Desc_fr']))
	{
	$Description_fr=$_POST['Desc_fr'];
	}
else
	{
	echo' Veuillez entrer une description, merci!';
	}
et
<tr>
							<td width="150" align="right">Fichier description fr :&nbsp;</td><td width="350" align="left"><input type="file" name="Desc_fr"/></td>
						</tr>
Par
<tr>
							<td width="150" align="right">Description fr :&nbsp;</td><td width="350" align="left"><input type="text" name="Desc_fr" size="40"/></td>
						</tr>
et quand j'envoi un post rien ne se passe
Donc si cous avez une autre solution , je suis preneur