Changement de donnée dans un script

Invité
Invité n'ayant pas de compte PHPfrance

27 sept. 2011, 09:57

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
<?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>
';
}

?>[/code]

et ceci est une page ou devrai etre inscrit la descritpion de l'objet 
[code]<?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>
';

?>

Petit nouveau ! | 6 Messages

27 sept. 2011, 16:36

Alors, dans un premier temps replace ton code html

Code : Tout sélectionner

<input type="file" name="Desc_fr"/>
par

Code : Tout sélectionner

<textarea cols="70" rows="10" name Desc_fr></textarea>
et pareil pour la description en anglais (en oubliant pas de changer les noms)

Pour ce qui est du traitement :

Remplace

Code : Tout sélectionner

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>"; }
par

Code : Tout sélectionner

if($_POST['Desc_fr'] != "") { $okDesc_fr="1"; } else { echo "La description FR n'a pas été renseignée<br>"; } if($_POST['Desc_en'] != "") { $okDesc_en="1"; } else { echo "La description EN n'a pas été renseignée<br>"; }
Ensuite :

tu enlève ça :

Code : Tout sélectionner

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"; }

Enfin tu remplace

Code : Tout sélectionner

print_external_file("Products/".$row['ID_Products']."/".$row['Description_fr']);
par

Code : Tout sélectionner

echo $row['Description_fr'];
Je ne sais pas si j'ai oublié des choses (ça m'arrive :P ). J'espère juste avoir été clair.

Ce n'est bien sûr pas la meilleure façon de traiter ton problème mais c'est celle qui je pense est la plus simple à appliquer en fonction de ton code.

Voile. Si tu as encore des questions n'hésite pas :D

Eléphanteau du PHP | 12 Messages

27 sept. 2011, 17:06

Déjà merci pour ton aide
j'ai bien suivis tes conseils et j'ai cette erreur qui aparais lorque j'envoi ma requete
Notice: Undefined index: Desc_fr in C:\Program Files\EasyPHP-5.3.8.0\www\mod\Adm_N.inc.php on line 15
La description FR n'a pas été renseignée

Notice: Undefined index: Desc_en in C:\Program Files\EasyPHP-5.3.8.0\www\mod\Adm_N.inc.php on line 23
La description EN n'a pas été renseignée
Le fichier 002P.jpg a bien été téléchargé
Il fait 28997 et est de type image/jpeg

Notice: Undefined index: ImgP1 in C:\Program Files\EasyPHP-5.3.8.0\www\mod\Adm_N.inc.php on line 41

Notice: Undefined index: ImgP1 in C:\Program Files\EasyPHP-5.3.8.0\www\mod\Adm_N.inc.php on line 48
Le fichier n'a pas été téléchargé
Le fichier 021.jpg a bien été téléchargé
Il fait 139022 et est de type image/jpeg
Le fichier 027.jpg a bien été téléchargé
Il fait 79607 et est de type image/jpeg
a la ligne 15 j'ai
		if($_POST['Desc_fr'] != "")
a la ligne 23
if($_POST['Desc_en'] != "")
Ligne 41
		if(is_uploaded_file($_FILES['ImgP1']['tmp_name']))
Ligne 48
			echo "Le fichier ".$_FILES['ImgP1']['name']." n'a pas été téléchargé<br>";

Eléphanteau du PHP | 12 Messages

27 sept. 2011, 17:30

Pour ce qui est des erreur 15 et 23 j'ai trouver ct un probleme de syntaxe
pas grave vu que j'ai trouver tout seul lol il fallais mettre
<textarea cols="70" rows="10" name="Desc_fr"></textarea>
au lieu de
<textarea cols="70" rows="10" name Desc_fr></textarea>
petit probleme de =et ""
pas grand chose mais pour ce qui est du reste je ne trouve pas
donc si vous avez une idée je suis toujours prenneur

Petit nouveau ! | 6 Messages

27 sept. 2011, 19:49

Essaye en ajoutant une condition a ce if :

Code : Tout sélectionner

if(isset($_FILES['ImgP1'])) if(is_uploaded_file($_FILES['ImgP1']['tmp_name']))

Eléphanteau du PHP | 12 Messages

27 sept. 2011, 20:36

Essaye en ajoutant une condition a ce if :

Code : Tout sélectionner

if(isset($_FILES['ImgP1'])) if(is_uploaded_file($_FILES['ImgP1']['tmp_name']))
Merci je n'ai plus d'erreur avec ca mais lorsque je remplis mon formulaire et envoi , ca ne se vois pas sur la page de destination
N'y aurais t'ill pas quelque chose a changer dans la bdd ? pour que les changement prennent effet ?

Eléphanteau du PHP | 12 Messages

28 sept. 2011, 13:46

svp J'ai vraiment besoin d'une aide pour savoir ou est l'erreur je ne la trouve pas je viens de passer toute la matinée a chercher pourquoi une fois que j'envoi cela ne s'affiche pas sur la page
Merci d'avance

Eléphanteau du PHP | 12 Messages

30 sept. 2011, 11:55

Merci pour tout touiks cela fonctionne nickem grace a tous tes conseils avisés