Réutiliser un code php dans une même page
Résolu
dona
-
dona -
dona -
Bonjour à tous,
je suis Clovis COULIBALY, étudiant en fin de cycle master à PIGIER Côte d'Ivoire Abidjan.
Dans mon application php en cours de développement, j'ai l'erreur suivante:
"Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\wamp\www\SOGETU\e-banque\titre.php on line 43"
voici le code:
<?php
include ("verifsess.php");
session_start();
$username="root";
$password="";
$hostname="127.0.0.1";
$nombase="ebanque";
if(!($connexion=mysqli_connect
($hostname,$username,$password)))
{
echo "<U>probleme lors de la connexion à MySql</U>";
exit();
}
if(!mysqli_select_db($connexion,$nombase))
{echo ("Erreur de selection de la base -->$nombase<--<br>");exit();}
$sql = "SELECT nom,prenom FROM client WHERE ident = '$_SESSION[aut]' and passwd = '$_SESSION[pss]'";
// execute requette SQL et renvoie un index
$ret=mysqli_query($connexion,$sql);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#0099CC">
<table width="759" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutDefaultTable-->
<tr>
<td width="297" height="30"></td>
<td width="54"> </td>
<td width="139" rowspan="2" valign="top"><strong><font color="#FFFFFF" size="6">SOGETU</font></strong></td>
<td width="235"> </td>
<td width="34"> </td>
</tr>
<tr>
<td rowspan="3" valign="top">
<?php
$client=mysql_fetch_array($ret); (LIGNE 43)
$prenom=$client['prenom'];
$nom=$client['nom'];
echo '<p><font color="#FFFFFF" size="-1"><strong>Bienvenue ';
echo "Mr </strong>$nom <em>$prenom</em></font></p>";
//echo "<td> $num_compte Mr $nom $prenom </td>";
?>
</td>
<td height="6"></td>
<td rowspan="2" valign="top"><strong><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif">Vos
Operations en ligne</font></strong></td>
<td></td>
</tr>
<tr>
<td height="12"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="1"></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="0"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
Merci d'avance pour votre aide!
je suis Clovis COULIBALY, étudiant en fin de cycle master à PIGIER Côte d'Ivoire Abidjan.
Dans mon application php en cours de développement, j'ai l'erreur suivante:
"Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\wamp\www\SOGETU\e-banque\titre.php on line 43"
voici le code:
<?php
include ("verifsess.php");
session_start();
$username="root";
$password="";
$hostname="127.0.0.1";
$nombase="ebanque";
if(!($connexion=mysqli_connect
($hostname,$username,$password)))
{
echo "<U>probleme lors de la connexion à MySql</U>";
exit();
}
if(!mysqli_select_db($connexion,$nombase))
{echo ("Erreur de selection de la base -->$nombase<--<br>");exit();}
$sql = "SELECT nom,prenom FROM client WHERE ident = '$_SESSION[aut]' and passwd = '$_SESSION[pss]'";
// execute requette SQL et renvoie un index
$ret=mysqli_query($connexion,$sql);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#0099CC">
<table width="759" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutDefaultTable-->
<tr>
<td width="297" height="30"></td>
<td width="54"> </td>
<td width="139" rowspan="2" valign="top"><strong><font color="#FFFFFF" size="6">SOGETU</font></strong></td>
<td width="235"> </td>
<td width="34"> </td>
</tr>
<tr>
<td rowspan="3" valign="top">
<?php
$client=mysql_fetch_array($ret); (LIGNE 43)
$prenom=$client['prenom'];
$nom=$client['nom'];
echo '<p><font color="#FFFFFF" size="-1"><strong>Bienvenue ';
echo "Mr </strong>$nom <em>$prenom</em></font></p>";
//echo "<td> $num_compte Mr $nom $prenom </td>";
?>
</td>
<td height="6"></td>
<td rowspan="2" valign="top"><strong><font color="#FFFFFF" face="Verdana, Arial, Helvetica, sans-serif">Vos
Operations en ligne</font></strong></td>
<td></td>
</tr>
<tr>
<td height="12"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="1"></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="0"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
Merci d'avance pour votre aide!
A voir également:
- Réutiliser un code php dans une même page
- Code ascii - Guide
- Supprimer une page dans word - Guide
- Comment déverrouiller un téléphone quand on a oublié le code - Guide
- Comment imprimer un tableau excel sur une seule page - Guide
- Code puk bloqué - Guide
2 réponses
Salut,
La fonction mysql_fetch_array(), comme toute les fonctions commençant mysql_*, fait partie de l'API php MySQL contrairement aux fonctions commençant par mysqli_* qui font partie de l'API php MySQLi.
Or tu ne peux pas mélanger l'utilisation de ces deux API comme ceci.
Pour corriger ton problème, il faut simplement que tu utilises la fonction mysqli_fetch_array() à la place de mysql_fetch_array().
https://www.php.net/manual/fr/mysqli-result.fetch-array.php
Bonne journée,
La fonction mysql_fetch_array(), comme toute les fonctions commençant mysql_*, fait partie de l'API php MySQL contrairement aux fonctions commençant par mysqli_* qui font partie de l'API php MySQLi.
Or tu ne peux pas mélanger l'utilisation de ces deux API comme ceci.
Pour corriger ton problème, il faut simplement que tu utilises la fonction mysqli_fetch_array() à la place de mysql_fetch_array().
https://www.php.net/manual/fr/mysqli-result.fetch-array.php
Bonne journée,