[POO] [PHP4] passage de variables d'un formulaire
bonjour tout le monde,
J'essaye de développer un site internet en php4/mysql pour ma femme. J'essaye en même temps d'apprendre la POO avec php4.
j'ai un petit soucis, j'ai une page Article.php qui va me générer un formulaire :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| <?php
class Article {
function AfficherCreerForm() {
Require_once('bdd/Bdd.php');
// remplir les listes
$sqlMar = 'SELECT * FROM MAR';
$sqlOff = 'SELECT * FROM OFF';
$sqlSou = 'SELECT * FROM SOU';
$sqlCat = 'SELECT * FROM CAT';
$reqMar = mysql_query($sqlMar) or die ('Erreur SQL !'.$sqlMar.'<br>'.mysql_error());
$reqOff = mysql_query($sqlOff) or die ('Erreur SQL !'.$sqlOff.'<br>'.mysql_error());
$reqSou = mysql_query($sqlSou) or die ('Erreur SQL !'.$sqlSou.'<br>'.mysql_error());
$reqCat = mysql_query($sqlCat) or die ('Erreur SQL !'.$sqlCat.'<br>'.mysql_error());
if (mysql_num_rows($reqMar) > 0) {
if (mysql_num_rows($reqOff)> 0) {
if (mysql_num_rows($reqSou) > 0) {
if (mysql_num_rows($reqCat) > 0) {
echo '<form method="post" action="Article.php">';
echo '<p >';
echo '<Table class="texte" bgcolor="#eefbdf" cellspacing="0" cellpadding="0" border="0" width="484px">';
echo '<tr><td width="15%" height="20px"></td><tr>';
//Liste Marque
echo ' <tr><td width="15%">';
echo ' <b> Marque </b> : </td><td width="25%"><select style="width: 130" id="Marque" name="Marque" size ="1">';
while($ligneMar = mysql_fetch_array($reqMar)) {
echo '<option value ="'.$ligneMar["IDMAR"].'">'.$ligneMar["MARLIBELLE"].'</option>'."\n";
}
echo' </select>';
echo' </td>';
//Liste Catégorie
echo'<td width="25%"><b> Catégorie </b> : </td><td width="25%"><select style="width: 110" id="Cat" name="Cat" size ="1">';
while($ligneCat = mysql_fetch_array($reqCat)) {
echo '<option value ="'.$ligneCat["IDCAT"].'">'.$ligneCat["CATLIBELLE"].'</option>'."\n";
}
echo' </select>';
echo' </td></tr>';
//Liste Offre
echo ' <tr><td width="15%"><b> Offre </b> : </td><td width="25%"><select style="width: 130" id="Offre" name="Offre" size ="1">';
while($ligneOff = mysql_fetch_array($reqOff)) {
echo '<option value ="'.$ligneOff["IDOFF"].'">'.$ligneOff["OFFLIBELLE"].'</option>'."\n";
}
echo' </select>';
echo' </td>';
//Liste SouCat
echo'<td width="25%"><b> Sous Catégorie </b> : </td><td width="25%"><select style="width: 110" id="SouCat" name="SouCat" size ="1">';
while($ligneSou = mysql_fetch_array($reqSou)) {
echo '<option value ="'.$ligneSou["IDSOU"].'">'.$ligneSou["SOULIBELLE"].'</option>'."\n";
}
echo' </select>';
echo' </td></tr>';
echo '<tr><td width="15%" height="20px"></td><tr>';
echo '</table>';
echo'</p>';
echo '<p >';
echo '<Table class="texte" bgcolor="#eefbdf" cellspacing="0" cellpadding="0" border="0" width="484px">';
echo '<tr><td width="15%" height="20px"></td><tr>';
echo '<tr><td width="15%" height="30px">';
echo '<b> Nom </b> : </td><td height="30px" width="25%"><input type="text" class="TexteChamps" id="Nom" name="Nom" size="25">';
echo' </td></tr>';
echo '<tr><td height="30px"><b> PUHT </b> : </td><td height="30px" width="25%"><input type="text" class="TexteChamps" id="PrixU" name="PrixU" size="10"> ';
echo' </td></tr>';
echo '<tr><td height="30px"><b> Référence </b> : </td><td height="30px" width="25%"><input type="text" class="TexteChamps" id="ref" name="ref" size="10">';
echo' </td></tr>';
echo '<tr><td height="30px"><b> Stock </b> : </td><td height="30px" width="25%"><input type="text" class="TexteChamps" id="stock" name="stock" size="10">';
echo' </td></tr>';
echo '<tr><td height="30px"><b> Contenu </b> : </td><td height="30px"></td></tr><tr><td height="20px"></td><td height="20px" width="25%"><textarea id="contenu" name="contenu" class="TexteChamps" rows="4" cols="40"></textarea>';
echo' </td></tr>';
echo '<tr><td height="30px"><b> Lien photo </b> : </td><td height="30px" width="25%"><input type="text" class="TexteChamps" id="Photo" name="Photo" size="42">';
echo' </td></tr>';
echo' <tr><td height="30px" ></td>';
echo' <td height="30px" align="center"><input type="reset" value="Effacer les données"><input type="submit" name="Ok" value="Enregistrer" ></td></tr>';
echo '<tr><td width="15%" height="20px"></td><tr>';
echo '</table>';
echo'</p>';
echo '</form>';
}
}
}
}
}
}
?> |
en gros j'aimerai pouvoir passer mes variables de mon formulaire vers une autre classe ART.class.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?php
class ART {
var $IdArt,$IdMar,$IdSou,$IdOff,$ArtLibelle,$ArtPUHT;
var $ArtContenu,$ArtRef,$ArtQteStock,$ArtPhoto;
//Fonction permettant la création d'un article dans la Table ART, on fait appelle à la page Bdd.php pour la connexion a la base de données.
//J'injecte mes variables dans ma requete qui est ensuite traitée.
//Je ferme ma connexion.
function CreerArt() {
Require_once('bdd/Bdd.php');
session_start();
$sql = 'INSERT INTO ART (idmar,idsou,idoff,artlibelle,artpuht,artcontenu,artref,artqtestock,artphoto) VALUES ("'.$_SESSION['Marque'].'","'.$_SESSION['SouCat'].'","'.$_SESSION['Offre'].'","'.$_SESSION['Nom'].'","'.$_SESSION['PrixU'].'","'.$_SESSION['contenu'].'","'.$_SESSION['ref'].'","'.$_SESSION['stock'].'","'.$_SESSION['Photo'].'")';
mysql_query($sql) or die ('Erreur SQL !'.$sql.'<br>'.mysql_error());
echo 'Votre article a bien été enregistré.';
mysql_close();
}
} |
en remplissant mon formulaire je voudrais quand je valide enregistrer mon article, mais pour ça je dois réussir à passer mes variables de la page Article.php à la page ART.class.php .
j'ai essayé de faire çà:
Require_once('ART.class.php');
$CreerArt = new ART('ART.class.php');
$CreerArt->CreerArt($_POST['variable'],....);
j'ai eu beaucoup de problemes avec ce procédé.
Voila, merci d'avance pour votre aide ;)