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

MySQLPHPphpmyadmin

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

add_vistor.php

<?php include 'connect.php'
$idd =$_GET['id'];
if(isset($_POST['add-visitor'])){

    $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"); 

HTML

<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>
        </div>
    </div>
  <!-- popup form -->
            <a class="overlay" id="login_form"></a>
               <div class="popup">
                 <h4>Add Visitor</h4>
               <div>
               <label>Name</label>
               <input type="text" name="name"/>
               </div>
               <div>
               <label>Date of Visit</label>
               <input type="date" name="date"/>
               </div>
               <div>
               <label>Time of Visit</label>
               <input type="time" name="time"/>
               </div>
               <div>
               <label>Affinity</label>
               <input type="text" name="aff"/>
               </div>
               <div>
               <label>Home Address</label>
               <input type="text" name="hadd"/>
               </div>


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


        </form>

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

http://localhost:8080/jailbsystem/admin2/admin_view.php?id=7#login_form

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 
(prisoner_id,
 visitor,
 date_of_visit,
 time_of_visit,
 affinity,
 homeAddress)
 VALUES 
 ($idd,
 $visitorr,
 '$datee',
 '$timee',
 '$aff',
 '$add')") or die($connect->error);