PDA

View Full Version : Warning: mysql_fetch_array() expects parameter 1...



channark
07 May 2011, 07:26 AM
i try to create a dinamique table but its not working this is the error :
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in .... ligne 7
here is the code :


<?php
$connection=mysql_connect("localhost","root","");
$val=$_GET['id'];
mysql_select_db("test_base2");
$requete = "SELECT * FROM `nature` WHERE id=$val";
$select=mysql_query($requete);
$row = mysql_fetch_array($select);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tableau</title>
</head>

<body>
<p>Afichage de l'image :<?php echo $row['name'];?></p>

<table border="1" cellspacing="0" cellpadding="5">
<tr>
<td>Nom</td>
<td><?php echo $row['name']; ?></td>
</tr>
<tr>
<td>Place</td>
<td><?php echo $row['place']; ?></td>
</tr>
<tr>
<td>Photo</td>
<td><img src="<?php echo $row['photo'];?>"/></td>
</tr>
</table>

</body>
</html>


thanks

MarPlo
07 May 2011, 01:36 PM
Perhaps there isn't "id=a_number" in URL adress.
Try this:

<?php
if(isset($_GET['id'])) {
$connection=mysql_connect("localhost","root","");
$val=$_GET['id'];
mysql_select_db("test_base2");
$requete = "SELECT * FROM `nature` WHERE id=$val";
$select=mysql_query($requete, $connection);
$row = mysql_fetch_array($select);
}
else { $row = array('name'=>'', 'place'=>'', 'photo'=>'') }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tableau</title>
</head>

<body>
<p>Afichage de l'image :<?php echo $row['name'];?></p>

<table border="1" cellspacing="0" cellpadding="5">
<tr>
<td>Nom</td>
<td><?php echo $row['name']; ?></td>
</tr>
<tr>
<td>Place</td>
<td><?php echo $row['place']; ?></td>
</tr>
<tr>
<td>Photo</td>
<td><img src="<?php echo $row['photo'];?>"/></td>
</tr>
</table>

</body>
</html>