Krish
Krish

Reputation: 1

connecting php to mysqli database error

i am having a problem in connecting this with the database. Please help whats wrong on this code?

<?php
$con = mysqli_connect('localhost','root','','ecommerce');
//getting the categories
function getCats(){
    global $con;
    $get_cats="select * from categories";
    $run_cats=mysqli_query($con, $get_cats);
    while($row_cats = mysqli_fetch_array($run_cats)){
        $cat_id=$row_cats('cat_id');
        $cat_title=$row_cats('cat_title');
        echo "<li><a href='#'>$cat_title</a></li>";
    }
}
//getting the brands
function getBrands(){
    global $con;
    $get_brands="select * from brands";
    $run_brands=mysqli_query($con, $get_brands);
    while($row_brands = mysqli_fetch_array($run_brands)){
        $brand_id=$row_brands('brand_id');
        $brand_title=$row_brands('brand_title');
        echo "<li><a href='#'>$brand_title</a></li>";
    }
}
?>

Upvotes: 0

Views: 115

Answers (1)

modsfabio
modsfabio

Reputation: 1147

You are accessing the $row_cats-Array and $row_brands-Array wrong.

Use [and ] instead of ( and )

Upvotes: 1

Related Questions