1

I'm trying to recode to work it with PHP7 but failing miserably. Could someone point me to the right direction?

Here's the error:

Warning: mysqli_query() expects at least 2 parameters, 1 given in /Applications/XAMPP/xamppfiles/htdocs/students/index.php on line 55

Fatal error: Uncaught Error: Call to undefined function mysql_fetch_array() in /Applications/XAMPP/xamppfiles/htdocs/students/index.php:57 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/students/index.php on line 57

PHP Code:

<?php
            include("db.php");
            $result=mysqli_query("SELECT * FROM students");
            while($test = mysql_fetch_array($result))
            {
                $id = $test['UID']; 
                echo "<tr align='center'>"; 
                echo"<td><font color='black'>" .$test['UID']."</font></td>";
                echo"<td><font color='black'>" .$test['FirstName']."</font></td>";
                echo"<td><font color='black'>". $test['LastName']. "</font></td>";
                echo"<td><font color='black'>". $test['Marks']. "</font></td>";
                echo"<td><font color='black'>". $test['RollNumber']. "</font></td>";    
                echo"<td> <a href ='view.php?UID=$id'>Edit</a>";
                echo"<td> <a href ='del.php?UID=$id'><center>Delete</center></a>";
                echo "</tr>";
            }
            mysql_close($conn);
            ?>

I have removed other unnecessary code and showing only the one which is creating error.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Elaine Byene
  • 3,868
  • 12
  • 50
  • 96
  • 1
    I closed an earlier question of yours http://stackoverflow.com/q/43707150/1415724 - I see you tried "something" but you can't just put in "one" mysqli_ function, the entire code needs to be using the same api; you can't mix `mysql_` with `mysqli_`. Many mysqli_ functions require a database connection to be the first argument. The duplicates contain reference links for you to look at and use that syntax. – Funk Forty Niner Apr 30 '17 at 14:41
  • Yeah. I have re-written everything. Thanks :) – Elaine Byene Apr 30 '17 at 14:41
  • You're welcome Elaine. I take it that you have gotten success now? – Funk Forty Niner Apr 30 '17 at 14:46
  • Yes. After a lot of reading :) – Elaine Byene Apr 30 '17 at 19:48
  • For those of you looking for solutions; I simply change all the `mysql` to `mysqli` and added `$conn` to lines such as `$result=mysqli_query($conn,"SELECT * FROM students");` and it began to work like a charm :) – Elaine Byene Apr 30 '17 at 19:49
  • Glad to hear that you solved this by yourself Elaine, *cheers* :-) – Funk Forty Niner Apr 30 '17 at 19:50

0 Answers0