Pb avec mysql_field_name() php5

Fermé
jmd13 - 16 nov. 2009 à 18:29
ProgMad Messages postés 88 Date d'inscription dimanche 4 mai 2008 Statut Membre Dernière intervention 15 août 2010 - 16 nov. 2009 à 22:34
Bonjour,

J'ai un petit problème avec ce scrypt. Il me retourne le message suivante :
Warning: mysql_field_name(): supplied argument is not a valid MySQL result resource in /var/www/mysql_send.php on line 60

J ai vérifié et reverifie la syntaxe de cette commande, je ne vois pas ou est l erreur.
/---------------------------------------------------------------------------------------------------------------------------------
/* Section that executes query and displays the results */

if(!empty($_POST['form']))

{

// connexion au serveur de données
$_SESSION['link'] = @mysqli_connect( $host, $user , $pwd);
// Pb a la connexion

if (!$_SESSION['link'])
{
echo "connexion serveur impossible";
exit;
}
else
{

// sélection de la base de données

if (@mysqli_select_db($_SESSION['link'], $_POST['database'] ) == False )
{
echo "connexion base de donnees impossible";
}
else
{
$_SESSION['connexion_base'] = "true";
}
}

$_SESSION['result'] = mysqli_query($_SESSION['link'],$_POST['query']);

echo "Database Selected: <b>{$_POST['database']}</b><br>

Query: <b>{$_POST['query']}</b>

<h3>Results</h3><hr>";

if($_SESSION['result'] == false)

{

echo "<h4>Error: ".mysqli_error($_SESSION['link'] )."</h4>";

}

elseif(@mysqli_num_rows($_SESSION['result'] ) == 0)

{

echo "<h4>Requete terminee.

Aucun resultat retourne.</h4>";

}

else

{

/* Display results */

echo "<table border='1'><thead><tr>";

for($i = 0;$i < (mysqli_num_fields($_SESSION['result']));$i++)

{
$names[] = mysql_field_name($_SESSION['result'], $i);
echo "<th>".$name[0]; "</th>";

}

echo "</tr></thead>

<tbody>";

for ($i=0;$i < mysqli_num_rows($_SESSION['result']);$i++)

{

echo "<tr>";

$row = mysqli_fetch_row($_SESSION['result']);

foreach($row as $value)

{

echo "<td>".$value."</td>";

}

echo "</tr>";

}

echo "</tbody></table>";

}

/* Display form with only buttons after results */

$query = str_replace("'","%&%",$_POST['query']);

echo "<hr><br>

<form action='{$_SERVER['PHP_SELF']}' method='POST'>

<input type='hidden' name='query' value='$query'>

<input type='hidden' name='database'

value={$_POST['database']}>

<input type='submit' name='queryButton'

value='New Query'>

<input type='submit' name='queryButton'

value='Edit Query'>

</form>";

exit();

}



/* Displays form for query input */

if (@$_POST['queryButton'] != "Edit Query")

{

$query = " ";

}

else

{

$query = str_replace("%&%","'",$_POST['query']);

}

?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>"

method="POST">

<table>

<tr><td style='text-align: right; font-weight: bold'>

Type in database name</td>

<td><input type="text" name="database"

value=<?php echo @$_POST['database'] ?> ></td>

</tr>

<tr><td style='text-align: right; font-weight: bold'

valign="top">Type in SQL query</td>

<td><textarea name="query" cols="60"

rows="10"><?php echo $query ?></textarea></td>

</tr>

<tr><td colspan="2" style='text-align: center'>

<input type="submit" value="Submit Query"></td>

</tr>

</table>

<input type="hidden" name="form" value="yes">

</form>

</body></html>
/*----------------------------------------------------------------------------------------------------------

Merci pour votre aide
Bonne journee
JMD13

1 réponse

ProgMad Messages postés 88 Date d'inscription dimanche 4 mai 2008 Statut Membre Dernière intervention 15 août 2010
16 nov. 2009 à 22:34
Salut

Refait le
         $_SESSION['result'] = mysqli_query($_SESSION['link'],$_POST['query']); 


juste avant la phrase où ta le warning .

A+
0