Formulaire d'ajout de produit

cs_samia22 Messages postés 16 Date d'inscription lundi 28 mars 2011 Statut Membre Dernière intervention 28 mai 2011 - 28 mai 2011 à 21:06
cod57 Messages postés 1653 Date d'inscription dimanche 7 septembre 2008 Statut Membre Dernière intervention 11 septembre 2013 - 28 mai 2011 à 22:56
Bonjour à tous ..
je fait mon formulaire d'ajout et ca marche bien..

mais il manque le test sur les champs de type entier et decimal....

vous pouvez m'aider.....

Voici le code:
connexion();
$ref= $_POST["reference"] ;

//$date2= $_POST["date2"] ;
if(isset($_POST['titre']) and isset($_POST['reference']) and isset($_POST['nomproduit']) and isset($_POST['description']) and isset($_POST['prix'])
and isset($_POST['marque']) and isset($_POST['promotion']) and isset($_POST['QteStock']) and isset($_POST['TVA']))
{
if(!empty($_POST['titre']) and !empty($_POST['reference']) and !empty($_POST['nomproduit']) and !empty($_POST['description']) and !empty($_POST['prix'])
and !empty($_POST['marque']) and !empty($_POST['promotion']) and !empty($_POST['QteStock']) and !empty($_POST['TVA']))
{

$sql1="select * from produit where reference='".$ref."'";
$resultat=mysql_query($sql1) or die('erreur');
if(mysql_num_rows($resultat)==0)
{

$sql = "insert into produit(reference,nomproduit,description,prix,idcategorie,marque,promotion,QteStock,TVA) values('".$ref."','".$_POST['nomproduit']."','".$_POST['description']."','".$_POST['prix']."',
'".$_POST['titre']."','".$_POST['marque']."','".$_POST['promotion']."','".$_POST['QteStock']."','".$_POST['TVA']."')";

$requete = mysql_query($sql) or die( mysql_error() ) ;
alerte("Le produit ".$_POST['nomproduit']." est ajoute avec succes");
}
else
alerte('le produit existant');
}else
alerte('Remplir les champs');
}

$chemin ='C:\Program Files\EasyPHP-5.3.3\www\boutiqueWMC\client\photos-livredor/';
// -------------------------------------------

// -------------------------------------------
// enregistrement des champs (autres que photo) dans la BD (par INSERT)
// recuperation du ID cree en selectionnant LA DERNIERE fiche cree
$query = 'SELECT MAX(idproduit) AS IDmax FROM produit';
$result = mysql_query($query) or die('Erreur SQL !
'.$query.'
'.mysql_error());
$val = mysql_fetch_array($result);
$IDnew = $val['IDmax'];
// -------------------------------------------

if(isset($_FILES['PHOTO']) && !empty ($_FILES['PHOTO']))
{
$PHOTOupload = $_FILES['PHOTO']['name'];
if ($PHOTOupload==""){
$PHOTOupload=$_POST['image'];
}
// Restrictions (accepter seulement les images, poids maxi, ...) :
$FileSizeMax = 2000000;
$ExtfichierOK = '" jpg jpeg png gif"';
// ... gestion des erreurs
// ...
// -------------------------------------------
// enregistrement de la photo dans le repertoire

$temp = $_FILES['PHOTO']['tmp_name'];
move_uploaded_file($temp, $chemin.$PHOTOupload);
// enregistrement du NOM de la photo dans la BD (par UPDATE)
$SQL = 'UPDATE produit SET img=\''.$PHOTOupload.'\' WHERE idproduit= '.$IDnew;
mysql_query($SQL);
}

Merci d'avance

4 réponses

cod57 Messages postés 1653 Date d'inscription dimanche 7 septembre 2008 Statut Membre Dernière intervention 11 septembre 2013 19
28 mai 2011 à 21:56
bonsoir
il existe des fonctions
http://www.manuelphp.com/php/function.is-int.php
is_numeric /*général*/
is_int
is_float
// d'autres
is_bool
is_string
is_array
is_object


donc je ferais
<!--
Bonjour à tous .. 
je fait mon formulaire d'ajout et ca marche bien.. 
mais il manque le test sur les champs de type entier et decimal.... 
vous pouvez m'aider..... 
Voici le code: 
-->
<?php
connexion(); 
$ref= $_POST["reference"] ; 

//$date2= $_POST["date2"] ; 
if(isset($_POST['titre']) and isset($_POST['reference']) and isset($_POST['nomproduit'])
and isset($_POST['description']) and isset($_POST['prix']) 
and isset($_POST['marque']) and isset($_POST['promotion']) 
and isset($_POST['QteStock']) and isset($_POST['TVA'])

){ 

    if(!empty($_POST['titre']) and !empty($_POST['reference']) and !empty($_POST['nomproduit']) and !empty($_POST['description']) and !empty($_POST['prix']) 
    and !empty($_POST['marque']) and !empty($_POST['promotion']) and !empty($_POST['QteStock']) and !empty($_POST['TVA'])
    and is_numeric($_POST['TVA']) and is_numeric($_POST['prix'])){ 
    
    $sql1="select * from produit where reference='".$ref."'"; 
    $resultat=mysql_query($sql1) or die('erreur'); 
      
      if(mysql_num_rows($resultat)==0){ 
      $sql = "insert into produit(reference,nomproduit,description,prix,idcategorie,marque,promotion,QteStock,TVA) values('".$ref."','".$_POST['nomproduit']."','".$_POST['description']."','".$_POST['prix']."', 
      '".$_POST['titre']."','".$_POST['marque']."','".$_POST['promotion']."','".$_POST['QteStock']."','".$_POST['TVA']."')"; 
      $requete = mysql_query($sql) or die( mysql_error() ) ; 
      alerte("Le produit ".$_POST['nomproduit']." est ajoute avec succes"); 
      }else{ 
      alerte('le produit existant');
      } 
    
    }else 
    alerte('Remplir les champs'); 
    } 

$chemin ='C:\Program Files\EasyPHP-5.3.3\www\boutiqueWMC\client\photos-livredor/'; 
// ------------------------------------------- 

// ------------------------------------------- 
// enregistrement des champs (autres que photo) dans la BD (par INSERT) 
// recuperation du ID cree en selectionnant LA DERNIERE fiche cree 
$query = 'SELECT MAX(idproduit) AS IDmax FROM produit'; 
$result = mysql_query($query) or die('Erreur SQL !
'.$query.'
'.mysql_error()); 
$val = mysql_fetch_array($result); 
$IDnew = $val['IDmax']; 
// ------------------------------------------- 

if(isset($_FILES['PHOTO']) && !empty ($_FILES['PHOTO'])){ 
$PHOTOupload = $_FILES['PHOTO']['name']; 
if ($PHOTOupload==""){ 
$PHOTOupload=$_POST['image']; 
} 
// Restrictions (accepter seulement les images, poids maxi, ...) : 
$FileSizeMax = 2000000; 
$ExtfichierOK = '" jpg jpeg png gif"'; 
// ... gestion des erreurs 
// ... 
// ------------------------------------------- 
// enregistrement de la photo dans le repertoire 

$temp = $_FILES['PHOTO']['tmp_name']; 
move_uploaded_file($temp, $chemin.$PHOTOupload); 
// enregistrement du NOM de la photo dans la BD (par UPDATE) 
$SQL = 'UPDATE produit SET img=\''.$PHOTOupload.'\' WHERE idproduit= '.$IDnew; 
mysql_query($SQL); 
} 
?>


Bonne programmation !
0
cs_samia22 Messages postés 16 Date d'inscription lundi 28 mars 2011 Statut Membre Dernière intervention 28 mai 2011
28 mai 2011 à 22:27
Bonsoir;
désolé mais il affiche une erreur:

Parse error : syntax error, T_ELSE inattendu dans C: \ Program Files \ EasyPHP-5.3.3 \ www \ boutiqueWMC \ administrator \ ajouterbd.php à la ligne 141
0
cs_samia22 Messages postés 16 Date d'inscription lundi 28 mars 2011 Statut Membre Dernière intervention 28 mai 2011
28 mai 2011 à 22:45
Bonsoir cod54;


merci beaucoup le code ca marche..

désolé mais je fait une erreur de bétise...

merci...

bonne soirée
0
cod57 Messages postés 1653 Date d'inscription dimanche 7 septembre 2008 Statut Membre Dernière intervention 11 septembre 2013 19
28 mai 2011 à 22:56
tu peux acceptée le reponse s.t.p.
a++

Bonne programmation !
0
Rejoignez-nous