I have two tables (client and drug) and I've created a form which will insert the information the user enters into these tables. A client can have many previous drug uses (shortened to drug) therefore I made a separate table for multiple drug use and I now need to link them. The client_id is auto-increment and so is the drug_id, however my drug_client_id isn't and I need it to be the same as the client_id (otherwise they won't link). I'm not too sure on how to do this so if anybody can help me out then I'd be highly grateful
I couldn't get it to work on one php file so I had to put the client and drug insert statement things in two different ones; so if you can help me in maybe getting them into only one as well, then I'd be even more grateful haha.
Please see my code below and help me, many thanks.
<html>
<head>
<title> Access Community Trust </title>
</head>
<body>
<form action="addclientwo.html" method="post">
First name: <input type="text" name="first_name">
<br>
Drug use: <input type="text" name="drug1">
<input type="text" name="drug2">
<input type="text" name="drug3">
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
Require("dbconnect.php");
//establishes connected to database
$first_name = $_POST['first_name'];
$stmt = $dbh->prepare("INSERT INTO client (first_name) VALUES (:first_name)");
$stmt->bindParam(':first_name', $first_name);
$stmt->execute();
?>
<?php
Require("dbconnect.php");
$drug1 = $_POST['drug1'];
$drug2 = $_POST['drug2'];
$drug3 = $_POST['drug3'];
$stmt = $dbh->prepare("INSERT INTO drug (drug1, drug2, drug3) VALUES (:drug1, :drug2, :drug3)");
$stmt->bindParam(':drug1', $drug1);
$stmt->bindParam(':drug2', $drug2);
$stmt->bindParam(':drug3', $drug3);
$stmt->execute();
?>
Btw, I'm making this for a homeless hostel so some of these clients may have taken drugs in the past (which they need on record); I'm not making some kind of drug dealership haha