0

Hey I am currently working on this code to create a list of students depending on an entry on a HTML form. I am receiving the following error:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in ..... on line 15.

I have made a lot of changes and rearrangements but can't seem to get it to work. Any hints of help would be absolutely amazing!!

The code is:

<?php
require_once 'connect.php';
mysql_select_db("db_ll20g11");

if ($_POST ['criterion'] == 'c'){
        $status = 'current';
        echo 'Current students list<br/>';
    }
    else{
        $status ='left';
        echo' Left Students list <br/>';
    }

    $listings = "SELECT * FROM student WHERE status ='".$status."'";
    $results = mysqli_query($listings, $connect);
    //mysqli_fetch_query not working
    while ($row = mysqli_fetch_array($results))
    {
    echo  'Name:' .$row['name'] . " " .' Date of Birth:' .$row['dateOfBirth'] . " " . 'Gender:' .$row['gender'] . " " .'Email:' .$row['email']. " ";
    }

     echo '<br />';
?>

Thank you.

Undo
  • 25,519
  • 37
  • 106
  • 129
user2341130
  • 1
  • 1
  • 1

2 Answers2

1

You just did confuse your parameter order.

See under http://php.net/mysqli_query:

Procedural style

mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

So, write:

$results = mysqli_query($connect, $listings);

And don't use mysql and mysqli in the same code: mysql_select_db("db_ll20g11"); won't work here in combination with mysqli.

Use:

$connect = new mysqli("host", "user", "pass", "db_ll20g11");
Community
  • 1
  • 1
bwoebi
  • 23,637
  • 5
  • 58
  • 79
0
mysqli_query($listings, $connect);

Should be

mysqli_query($connect, $listings);

The link is the first parameter when specifying it, making the query the second parameter.

Ryan
  • 3,552
  • 1
  • 22
  • 39