Mysql – make a database where an ID can have multiple records


I am currently making an inmate information system in which the admin can insert multiple visitations records for a certain prisoner

This what my prisoner table looks like
prisoner table

Visitations table:
visitations table

I want it to be like this

expected db

I found out that it has something to do with my database but I'm struggling how to fix it. What should I do or change?

Also, This is my query for inserting which has an error "Undefined index: id"
I am trying to add a visitor in prisoner id = 7


<?php include 'connect.php'
$idd =$_GET['id'];

    $id = $row['prisoner_id'];
    $visitorr = $_POST['name'];
    $datee = $_POST['date'];
    $timee = $_POST['time'];
    $aff = $_POST['aff'];
    $add = $_POST['hadd'];

    $result2 = $connect->query("INSERT INTO visitations (visitor,date_of_visit,time_of_visit,affinity,homeAddress) 
        VALUES ('$visitorr','$datee','$timee','$aff','$add') WHERE id = '$idd'") 
        or die($connect->error);

    header("Location: admin_view.php"); 


<form method = 'post' action = 'add_visitor.php' enctype='multipart/form-data'>
     <link rel="stylesheet" href="add.css">

     <input type = 'hidden' name = 'submitted' value = 'true'>
  <!-- POPUP BUTTON       -->             
    <div class="main">
        <div class="#">
            <a href="#login_form" id="login_pop" class = 'add'>Add</a>
  <!-- popup form -->
            <a class="overlay" id="login_form"></a>
               <div class="popup">
                 <h4>Add Visitor</h4>
               <input type="text" name="name"/>
               <label>Date of Visit</label>
               <input type="date" name="date"/>
               <label>Time of Visit</label>
               <input type="time" name="time"/>
               <input type="text" name="aff"/>
               <label>Home Address</label>
               <input type="text" name="hadd"/>

               <input type="submit" value="Add Visitor" name = "add" class = 'add'/>
               <?php echo "<a href ='admin_view.php?id=$id' class='close'></a>"; 


This is what my url looks like when I add record to prisoner id = 7, is it right?


Thank you in advance.

Best Answer

On an insert you don't need a WHERE clause and the error you are getting is because you don't have a column named id in your visitations table. Change your insert query to

$result2 = $connect->query("INSERT INTO visitations 
 '$add')") or die($connect->error);