Error php mysql

1

I have the following code tells me the errors:

  

mysql_query () expects parameter 2 to be resource, string given in   C: \ AppServ \ www \ tableentradaysalida \ index.php on line 35

  

mysql_error () expects parameter 1 to be resource, null given in   C: \ AppServ \ www \ tableentradaysalida \ index.php on line 35 database   error:

line 35 is this:

$resultset = mysql_query($conn, $sql) or die("database error:". mysql_error($conn));
<tbody>
<?php
$sql = "SELECT emp_id, emp_name, emp_email, emp_salary, emp_age FROM emp ORDER BY emp_id DESC LIMIT 10";
$resultset = mysql_query($conn, $sql) or die("database error:". mysql_error($conn));
if(mysql_num_rows($resultset)) {
while( $rows = mysql_fetch_assoc($resultset) ) {
?>
<tr>
<td><?php echo $rows['emp_id']; ?></td>
<td><?php echo $rows['emp_name']; ?></td>
<td><?php echo $rows['emp_email']; ?></td>
<td><?php echo $rows['emp_salary']; ?></td>
<td><?php echo $rows['emp_age']; ?></td>
</tr>
<?php } } else { ?>
<tr><td colspan="5">No records to display.....</td></tr>
<?php } ?>
</tbody>

What is the error? Could you help me please?

    
asked by Grindor 23.05.2018 в 00:12
source

1 answer

1

The first error tells you that the second parameter must be a resource, not a string. In your case, you are sending the parameters to the mysql_query function in the wrong order. The right one would be:

$resultset = mysql_query($sql, $conn) or die("database error:". mysql_error($conn));

I have indicated the correction for mysql_query because I suppose you are working on an old project, but on the other hand, as they say in the comments, the mysql_query function is obsolete, you should use mysqli_query or pdo. The case of mysqli_query is easy:

$resultset = mysqli_query($conn, $sql) or die("database error:". mysql_error($conn));
    
answered by 23.05.2018 / 00:33
source