Input the codes in database

Hi,
I want to input the codes in my DB, which respecte each name.
I d’ont understand the error on the line 19:indicate:
Call to a member function prepare() on a non-object in C:\wampserver32\www\good\index.php on line 19
line 19 is: $result = $namedb->prepare("SELECT
can someone help me to correct it ?

index.php

<table border="1" cellspacing="0" cellpadding="2" >

<thead>
    <tr>
        <th>  Name </th>        
           <th> Code </th>
        <th> Action </th>
    </tr>
</thead>
<tbody>

    <?php
        $hostdb = 'localhost';
        $namedb = 'testebase';
        $userdb = 'root';
        $passdb = '';        

        $result = $namedb->prepare("SELECT 
                                   name,                                  
                                                                  code                   
                                                                  FROM trybase");                                                                      
        $result->execute();
    for($i=0; $row = $result->fetch(); $i++){
    ?>
    <tr class="record">
    <td><?php echo $row['name']; ?></td>        
        <td><?php echo $row['num']; ?></td>
        <td><a href="panier.php?name=<?php echo $row['name']; ?>"> edit </a></td>
    </tr>
    <?php
        }
    ?>
</tbody>
</table>

panier.php
<?php

        $hostdb = 'localhost';
        $namedb = 'testebase';
        $userdb = 'root';
        $passdb = '';    

    $name=$_GET['name'];
    $result = $db->prepare("SELECT * FROM trybase WHERE name= :userid");
    $result->bindParam(':userid', $name);
    $result->execute();
    for($i=0; $row = $result->fetch(); $i++){
?>

<form action="edit.php" method="POST">
 Name<br>
<input type="text" name="fname" value="<?php echo $row['name']; ?>" /><br>
Number<br>
<input type="text" name="Code" value="<?php echo $row['code']; ?>" /><br>
<input type="submit" value="Save" />
</form>
<?php

    }
?>

edit.php
<?php

        $hostdb = 'localhost';
        $namedb = 'testebase';
        $userdb = 'root';
        $passdb = '';
    
$name = $_POST['name'];
$num = $_POST['num'];
// query
$sql = "UPDATE trybase 
        SET name=?, num=?
    WHERE name=?";
$q = $db->prepare($sql);
$q->execute(array($name,,$code));
header("location: index.php");
?>

Is where you have PDO connect to MySQL in another file?

it connects only my DB: testebase