0

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>";
    }
}
?>
4
  • 2
    What's the error Commented Apr 20, 2017 at 18:37
  • Why do you think something is wrong with the code? What actual problem are you trying to solve? Commented Apr 20, 2017 at 18:37
  • If you are having connection issues check for the error, php.net/manual/en/mysqli.connect-error.php. Commented Apr 20, 2017 at 18:38
  • Please use the mysqli_query($con, $query) or die(mysqli_error($con));. This will give you the error Commented Apr 20, 2017 at 18:44

1 Answer 1

1

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

Use [and ] instead of ( and )

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.