0
votes

I downloaded this website directory and when I ran it, I received the following error:

Error

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'u471047401_test.Categories' doesn't exist' in /home/u471047401/public_html/inc/blocks/sidebar.php:13 Stack trace: #0 /home/u471047401/public_html/inc/blocks/sidebar.php(13): PDOStatement->execute(Array) #1 /home/u471047401/public_html/index.php(6): require('/home/u47104740...') #2 {main} thrown in /home/u471047401/public_html/inc/blocks/sidebar.php on line 13

Code

<?
    $cat = $_GET['cat'];
    if(empty($cat))
    {
        $cat = 0;
    }
    $menu_query = ("
        SELECT cat_id, cat_name, parent_cat
        FROM Categories
        WHERE (cat_id = ? OR parent_cat = ?)");

    $stm = $conn->prepare($menu_query);
    $stm->execute(array($cat, $cat));
    ("u471047401_test.Categories");
    $categories = $stm->fetchAll();
?>

<div class='col-4 col-lg-4 ' style='padding-left:0;'>
    <ul class="nav nav-pills nav-stacked well;">

<?
    foreach($categories as $categories_row)
    {
        $act = $categories_row['cat_id'] == $cat ? 'active' : '';
        echo"
        <li class={$act}>
            <a href='category.php?cat={$categories_row['cat_id']}'>
                {$categories_row['cat_name']}
            </a>
        </li>";

        if($categories_row['cat_id'] == $cat && $categories_row['cat_id'] > 0)
        {
            $back_link = "<li><a href=``'category.php?cat={$categories_row['parent_cat']}' title='Go back to previous category'>Back</a></li>";
        }
    }
?>

<?= $back_link ?>

    </ul>
</div>

What is causing this error?

1
Delete the single quotation marks which covers the 'FROM' - Ozan Kurt

1 Answers

3
votes

Remove the quotes around FROM

SELECT cat_id, cat_name, parent_cat  FROM  Categories
                                    ^----^-----here

If you put quotes around it then the DB engine will handle this as a static string and not as a keyword of your query.