Uncaught Error: Call to undefined function mysql_fetch_array()

Uncaught Error: Call to undefined function mysql_fetch_array() in C:\xampp\htdocs\GDB\MPT.php:72 Stack trace: #0 {main} thrown in C:\xampp\htdocs\GDB\MPT.php on line 72
I have this error while trying to run this command
can you help me find out what is wrong?


$con = mysqli_connect("localhost", "root", "");

    $choose = $_POST['searchkind'];
    $engine = $_POST['id'];

        $query = "SELECT * FROM GDB where $choose='$engine' ";
            $query_run = mysqli_query($con,$query);


        while($row = mysql_fetch_array($query_run))
        <font size=10px face="Helvetica">
            <br><table style="background-color:#f8f8ff">
                    <td><?php echo $row['iid'] ?></td>
                    <td><?php echo $row['iname'] ?></td>
                    <td><strong>Atomic Number:</strong></td>
                    <td><?php echo $row['Atnum'] ?></td>
                    <td><strong>Mass Number:</strong></td>
                    <td><?php echo $row['Mnum'] ?></td>


The mysql* function were removed from PHP some while ago. You should be using mysqli* or better still PDO.

still when i use mysqli_fetch_arrey still gets the error

in this case i get this
Uncaught TypeError: mysqli_fetch_array(): Argument #1 ($result) must be of type mysqli_result, bool given in C:\xampp\htdocs\GDB\MPT.php:72 Stack trace: #0 C:\xampp\htdocs\GDB\MPT.php(72): mysqli_fetch_array(false) #1 {main} thrown in C:\xampp\htdocs\GDB\MPT.php on line 72

Does that line need an “i”?

ik but also when i add it nothing changes it still gives me the same error

But it’s not the same error. It’s quite a different error.

Your query failed.

Go back to where you executed the query, and find out what mysql is telling you is wrong (echo mysqli_error();)

In your query you use an identifier GDB but it has no value assigned to it.
Do you think that that might be a problem?

  • Can you supply GDB sql table structure?
  • Are you sure that $_POST['searchkind'] is a field in the GDB table? Any other value will pass an error.
  • If the field is correct, are you sure that $_POST['id'] is not empty when $_POST['search'] is SET?

That… that’s the table name. It wont have a value. It’s a table in the database.

You’re vulnerable to SQL Injection attacks with that code. You should always use prepared statements when plugging any data into a query, no matter what the source of the data is or how well you trust the source of the data

Then it should be quoted.
There is a world of difference between GDB and “GDB”, as you said it doesn’t have a value so your query is trying to access a table without a name. If you captured errors you would probable get an error that the parameter is expecting a string not null.

The original query is enclosed with double quotes. Enclosing the table name with double quotes would produce a syntax error. Backticks should be used for quoting table names and columns.

Table references go in backticks. They also dont NEED to go in backticks (in MOST cases). The database engine will interpret whatever comes immediately after FROM as a table reference (unless it runs into a reserved word token, like SELECT, which is when backticks become mandatory, if for some reason you decided to use a reserved word as a table or database name).

1 Like