Problème PHP

Résolu
Bonjour à tous,

Voilà je suis super débutant en php et j'ai un soucis avec mon code mais je ne comprends rien (pour être honnête)...

Cela fait maintenant 3 jours que je me casse les dents la dessus et j'espère que vous pourrez m'aider.

Voici le message erreur:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /opt/guide/www.amisprl.be/HTML/mcvs/admin.php on line 40

Voici mon code:

<?php

include("variables.inc.php");
include("identification.inc.php");
include("haut.inc.php");

$liendb = mysql_connect ("localhost", "user", "pass")
mysql_select_db ("db");

?>

<p align="left"> Acceuil dossier client</p>

<form action="admin.php" method="post">
<input type="text" name="motclef" value="<?php echo $_REQUEST['motclef']; ?>" />  
<input type="submit" value="rechercher">
</form>

<table width="90%" align="center" border="1">
<tr>
<td class="intitule">Numéro client</td>
<td class="intitule">Société</td>
<td class="intitule"> </td>
</tr>

<?php

$clause = '';
if (isset($_REQUEST['motclef']))
{
$clause .= " WHERE INSTR(nom,'".$_REQUEST ['motclef']."')";
$clause .= " OR INSTR(id,'".$_REQUEST ['motclef']."')";
}

$sql = "SELECT FROM clients ".$clause;
$resultat = mysql_query ($sql);

while ($clients = mysql_fetch_array ($resultat)) ==>> la ligne qui me renvoi l'erreur.

{
$id = $clients['id_client'];
$nom = $clients['Societe'];

echo "<tr>";
echo "<td>$id</td>";
echo "<td>$nom</td>";
echo "<td>";
echo "<a href='clients_edit.php?id=$id'>voir</a>";
echo "</td>";
echo "</tr>";

}

echo "</table>";

?>

<?php
mysql_close($liendb);
include("bas.inc.php");
?>

Merci d'avance à ceux qui prendront un peu de leurs temps pour m'aider.
Configuration: Windows Vista Internet Explorer 7.0

6 réponses

  1. J 'ai ajouté un or die(mysql_error()); sur la ligne précedente.

    Voici le code qui fonctionne:

    <?php

    include("variables.inc.php");
    include("identification.inc.php");
    include("haut.inc.php");

    $liendb = mysql_connect ("localhost", "user", "pass")
    mysql_select_db ("db");

    ?>

    <p align="left"> Acceuil dossier client</p>

    <form action="admin.php" method="post">
    <input type="text" name="motclef" value="<?php echo $_REQUEST['motclef']; ?>" />
    <input type="submit" value="rechercher">
    </form>

    <table width="90%" align="center" border="1">
    <tr>
    <td class="intitule">Numéro client</td>
    <td class="intitule">Société</td>
    <td class="intitule"> </td>
    </tr>

    <?php

    $clause = '';
    if (isset($_REQUEST['motclef']))
    {
    $clause .= " WHERE INSTR(nom,'".$_REQUEST ['motclef']."')";
    $clause .= " OR INSTR(id,'".$_REQUEST ['motclef']."')";
    }

    $sql = "SELECT FROM clients ".$clause;
    $resultat = mysql_query ($sql) or die(mysql_error());

    while ($clients = mysql_fetch_array ($resultat))

    {
    $id = $clients['id_client'];
    $nom = $clients['Societe'];

    echo "<tr>";
    echo "<td>$id</td>";
    echo "<td>$nom</td>";
    echo "<td>";
    echo "<a href='clients_edit.php?id=$id'>voir</a>";
    echo "</td>";
    echo "</tr>";

    }

    echo "</table>";

    ?>

    <?php
    mysql_close($liendb);
    include("bas.inc.php");
    ?>

    Voilà, encore merci pour ton aide
    0
    1. merci à tous pour votre aide, maintenant cela fonctionne
      0
      1. Contributeur
        T'as solutionné comment ?
        0
    2. si par paramètres nul tu entends dans la structure de ma table colonne NULL tout est sur non sinon c'est que je comprends pas, je m'en excuse car suis vraiment super débutant. Encore merci pour ton aide.
      0
      1. Ca c'est bon j'avais oublié la virgule.

        Par contre il me renvoi tjs le premier message comme au départ malgrés la correction que tu m'as indiqué.

        mysql_fetch_array(): supplied argument is not a valid MySQL result resource ligne 40

        revoici le code:

        <?php

        include("variables.inc.php");
        include("identification.inc.php");
        include("haut.inc.php");

        $liendb = mysql_connect ("localhost", "", "")

        mysql_select_db ("db");

        ?>

        <p align="left"> Acceuil dossier client</p>

        <form action="admin.php" method="post">
        <input type="text" name="motclef" value="<?php echo $_REQUEST['motclef']; ?>" />  
        <input type="submit" value="rechercher">
        </form>

        <table width="90%" align="center" border="1">
        <tr>
        <td class="intitule">Numéro client</td>
        <td class="intitule">Société</td>
        <td class="intitule"> </td>
        </tr>

        <?php

        $clause = '';
        if (isset($_REQUEST['motclef']))
        {
        $clause .= " WHERE INSTR(nom,'".$_REQUEST ['motclef']."')";
        $clause .= " OR INSTR(id,'".$_REQUEST ['motclef']."')";
        }

        $sql = "SELECT FROM clients ".$clause;
        $resultat = mysql_query ($sql,$liendb);

        while ($clients = mysql_fetch_array ($resultat)) ==>> ligne à problème

        {
        $id = $clients['id_client'];
        $nom = $clients['Societe'];

        echo "<tr>";
        echo "<td>$id</td>";
        echo "<td>$nom</td>";
        echo "<td>";
        echo "<a href='clients_edit.php?id=$id'>voir</a>";
        echo "</td>";
        echo "</tr>";

        }

        echo "</table>";

        ?>

        <?php
        mysql_close($liendb);
        include("bas.inc.php");
        ?>

        Merci de m'aider, c'est super sympa
        0
        1. Contributeur
          Dans ton mysql, y a-t-il 2 paramètres nuls ou tu nous les caches (je dis pas ça pour t'embêter, mais tu as peut-être oublié) ?
          0
      2. J'ai fais la modification et maintenant je n'accède plus au fichier j'ai directement une erreur :

        Parse error: syntax error, unexpected T_VARIABLE in /opt/guide/HTML/mcvs/admin.php on line 38
        0
        1. Contributeur
          Elle correspond à quoi la ligne 38 ?
          0
      3. Contributeur
        $resultat = mysql_query ($sql,$liendb);
        0