8792 sujets

Développement web côté serveur, CMS

Salut,

j'ai un petit problème, j'ai réalisé une page PHP que je veux passer en template (avec vtemplate), seulement, une fois passé en template, il m'annonce une erreur du type :

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /www/sites/1/T/O/toulokowitz.com/administration/class/maclass.inc.php on line 27


Voici ma classe :


<?php
class basededonnees {
                // déclaration de variables
                var $serveur;
                var $login;
                var $pass;
                var $requete;
                var $combien;
                var $resultat;
                var $base;
                // fonction base de données
                function basededonnees($s,$l,$p,$b) {
                        $this->serveur=$s;
                        $this->login=$l;
                        $this->pass=$p;
                        $this->base=$b;
                        $this->connexion();
                }
                // connexion à la base
                function connexion() {
                        mysql_connect($this->serveur,$this->login,$this->pass);
                        mysql_select_db($this->base);
                }
                // envoi de la requete
                function requete($req) {
                        $this->resultat=mysql_query($req);
***ligne 27 *** $this->combien=mysql_num_rows($this->resultat);
                }
                // affichage objets
                function suivant() {
                $d=mysql_fetch_object($this->resultat);
                return ($d);
                }
                function suivant2() {
                $d2=mysql_fetch_object($this->resultat);
                return ($d);
                }
}
?>


Voici mon code PHP pour les templates :


<?php  session_start();
(isset($HTTP_POST_VARS["nom"])) ? $produit = trim($HTTP_POST_VARS["nom"]) : $produit = "";
(isset($HTTP_POST_VARS["nom2"])) ? $produit2 = trim($HTTP_POST_VARS["nom2"]) : $produit2 = "";
include("include/config.inc.php");
include("class/vtemplate.class.php");
include("class/maclass.inc.php");
include("lib/malibrairie.php");
$vtp = new VTemplate;
$page = $vtp->Open("affiche.htm");
$vtp->setVar($page,"login",$l=login());
$ban = new basededonnees("10.0.5.190",USER,PASS,BASE);
$counter = 0;
$ban->requete("SELECT * FROM produits WHERE");
if ($produit !== "") {
                $ban->requete .= "nom_prod like '%$produit%'";
                $counter++;
}
if ($produit2 !== "") {
                $ban->requete .= "nom_prod like '%$produit2%'";
                $counter++;
            }

$vtp->AddSession($page,"ligne"); //ouverture de session

if (empty($produit)) {     //si le champ de recherche est vide -> $produit=nom écrire :
     $vtp->setVar($page,"ligne.nom",$d-> nom_prod);
     $vtp->setVar($page,"ligne.photo",$d-> photo_prod);
     $vtp->setVar($page,"ligne.description",$d-> description_prod);
}
else  //sinon
{
if ($produit !== $d->nom_prod) { //si $produit=nom est vide mais ne correspond pas a un nom de la db, ecrire :
        echo "Le produit n'existe pas ou vous avez entrez un nom incorect.<br /><a href='prive.php'>Recommencer la recherche</a>";
}
else {  //sinon, afficher :
     $vtp->setVar($page,"ligne.nom",$d-> nom_prod);
     $vtp->setVar($page,"ligne.photo",$d-> photo_prod);
     $vtp->setVar($page,"ligne.description",$d-> description_prod);
}
}

$vtp->CloseSession($page,"ligne");  //fermeture de session

$vtp->Display($page);
?>


Et, au cas ou, le code PHP fonctionnel n'étant pas en templates :


<?php
            (isset($HTTP_POST_VARS["nom"])) ? $produit = trim($HTTP_POST_VARS["nom"]) : $produit = "";
            (isset($HTTP_POST_VARS["nom2"])) ? $produit2 = trim($HTTP_POST_VARS["nom2"]) : $produit2 = "";
            include("include/config.inc.php");
            $connex=mysql_connect("10.0.5.190", USER, PASS);
            $base=mysql_select_db(BASE);
            $counter = 0;
            $req = "SELECT * FROM produits WHERE ";
            if ($produit !== "") {
                $req .= "nom_prod like '%$produit%'";
                $counter++;
            }
            if ($produit2 !== "") {
                $req .= "nom_prod like '%$produit2%'";
                $counter++;
            }
            $res=mysql_query($req);
            $data=mysql_fetch_object($res);
            //$nomproduit=$data->id_prod;
            if (empty($produit)) {
            echo $data->nom_prod ;
            echo "<br />";
            echo "<img src='http://www.toulokowitz.com/photos/$data->photo_prod' />";
            echo "<br />";
            echo $data->description_prod ;
            echo "<br />";
            echo "<a href='modif.php'>Modifier</a><a href='supp.php'>Supprimer</a>";
            }
            else {
            if ($produit !== $data->nom_prod) {
            echo "Le produit ".$produit." n'existe pas ou vous avez entrez un nom incorect.<br /><a href='prive.php'>Recommencer la recherche</a>";
            }
            else {
            echo $data->nom_prod ;
            echo "<br />";
            echo "<img src='http://www.toulokowitz.com/photos/$data->photo_prod' />";
            echo "<br />";
            echo $data->description_prod ;
            echo "<br />";
            echo "<a href='modif.php'>Modifier</a><a href='supp.php'>Supprimer</a>";
            }
            }
            ?>


Bon, inutile de vous dire que je ne suis pas un pro en PHP Smiley rolleyes

Merci pour tout.
Modifié par TheReverendEVIL (26 Apr 2006 - 17:24)