0

Hi can u guys help me with this error ?

"Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in "blablabla" on line 31."

I've tried a lot of solutions that I've found but it still leads me to this error.

<html>
    <head>
        <title>
            Autores
        </title>
    </head>
    <body>
        <?php        
$link = mysqli_connect("", "", "", "");
if($link === false){
    die("ERRRO: Não foi possivel a conexão com a base de dados. " . mysqli_connect_error());
}        
$sql = 'SELECT * FROM autores';
$result = mysqli_query($link, $sql) or die($sql."<br/><br/>".mysql_error());        
echo "<p><b>Ver todos</b> | <a href='view-paginated.php?page=1'>Ver por página</a></p>";       
echo "<table border='1' cellpadding='10'>";        
echo "<tr> <th>ID</th> <th>Autor</th><th></th> <th></th></tr>";        
while($row = mysqli_fetch_array($result )) {  
    // echo out the contents of each row into a table
    echo "<tr>";   
    echo '<td>' . $row['a_id'] . '</td>'; 
    echo '<td>' . $row['a_nome'] . '</td>';
    echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
    echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
    echo "</tr>";
}
// close table>
echo "</table>";
        ?>
        <p>
            <a href="new.php">Add a new record</a>
        </p>
    </body>
</html>

Thanks,

Gonçalo Pinho

2 Answers2

1
while($row = mysqli_fetch_array($result )) {  //you have to change mysql to mysqli
    // echo out the contents of each row into a table
    echo "<tr>";   
    echo '<td>' . $row['a_id'] . '</td>'; 
    echo '<td>' . $row['a_nome'] . '</td>';
    echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
    echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
    echo "</tr>";
}
0

Why can't you do like this

$link = mysqli_connect("HOST", "UNAME", "PASS", "Database");

$query = "SELECT * FROM autores";
$result = $link->query($query);

while($row = $result->fetch_array())
{
// Your stuff
}
Akshay
  • 700
  • 9
  • 23