Got this type of errors:

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\OpenServer\domains\Test.loc\PHP\Shop Cart\index.php on line 7

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\OpenServer\domains\Test.loc\PHP\Shop Cart\index.php on line 8

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\OpenServer\domains\Test.loc\PHP\Shop Cart\index.php on line 11

//Config File
<?php
    session_start();
    $connect = mysqli_connect ('localhost', 'test', 'password')
    or die(mysqli_error());
    mysqli_select_db($connect, 'training');

?>




<?php

    include_once('config.php');


function findProducts() {
    $query = mysqli_query ($connect, "SELECT * FROM cart");
    $result = mysqli_fetch_array($query);


    while($row = mysqli_fetch_array( $result)){
        echo $row['title'].'<br>';
    }
}


findProducts();
?>

It happens because $connect is defined out of the scope of the function, to fix it do:

<?php

include 'config.php';

function findProducts($connect) {
    $query = mysqli_query($connect, "SELECT * FROM cart");
    while($row = mysqli_fetch_assoc($query)){
        echo $row['title'].'<br>';
    }
}

echo findProducts($connect)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.