Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:28:43+00:00 2026-06-18T05:28:43+00:00

Okay, I am trying to submit values from a php form into multiple tables.

  • 0

Okay, I am trying to submit values from a php form into multiple tables. My php code is working fine but values such as patientID are inserting into “patients” for example: PatientID; 100 fine but the same value for PatientID is not inserting the same unique value into another table for example: the “Disease” table. Am I doing something wrong?

**revised question

I’m not sure if I have the relationships between the tables correctly assigned. Here are the tables and the relationships between them.

Patient Attends Accident & Emergency 
Patient seen_by Nurse
Nurse assesses disease of patient 
{{nurse assigns priority to patient}} Priority linked to patient and nurse
{{nurse gives patient waiting time}} Time linked to nurse and patient 
{{doctor will see patient based on their waiting time and priority}} Doctor linked to both time and priority. 
Accident & Emergency; (ID(PK), PatientID(FK) Address, City, Postcode, Telephone)
Patient (ID(PK), Forename, Surname, Gender, Dateofbirth, Address, Patienthistory, illness, 
Nurse(ID(PK) Forename, surname)
Assesses(ID(PK)NurseID(FK), PatientID(FK))
Disease(ID(PK), illness, symptoms, diagnosis, treatment) {{nurse assesses disease of patient (these tables should all be linked}}
Priority (ID, NurseID(FK), PatientID(FK), DoctorID(FK), Priority)
Time(ID,NurseID, PatientID, DoctorID, Arrival Time, Expected waiting time, Discharge time)
Doctor (ID,Firstname, Surname)

Revised PHP code. ID is not inserting into tables; for example: PatientID is not inserting into the Disease table.

<?php
$con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error());
mysql_select_db("a&e", $con) or die('Could not select database.');

//get NURSE values from form
$nurse_ID = $_POST['nurse_ID'];
$nurse_name = $_POST['nurse_name'];
$nurse_lastname = $_POST['nurse_lastname'];

//get Disease values from form
$disease_ID = $_POST['disease_ID'];
$symptoms = $_POST['symptoms'];
 $diagnosis = $_POST['diagnosis'];
$treatment = $_POST['treatment'];

//get Patient values from form 
$patient_id = $_POST['patient_id'];
$patient_name = $_POST['patient_name'];
$patient_lastname = $_POST['patient_lastname'];
$gender = $_POST['gender'];
 $dateOfBirth = $_POST['dateOfBirth'];
$monthOfBirth = $_POST['monthOfBirth'];
$yearOfBirth = $_POST['yearOfBirth'];
$address = $_POST['address'];
$history = $_POST['history'];
$illness = $_POST['illness'];
$priority = $_POST['priority'];
$priority_id = $_POST['priority_id'];

// Validate
$date = $dateOfBirth.'-'.$monthOfBirth.'-'.$yearOfBirth;

$sql ="INSERT INTO Nurse(Forename, Surname)
VALUES('$nurse_name', '$nurse_lastname')";
mysql_query($sql,$con) or die('Error: ' . mysql_error());
echo "$nurse_ID"; mysql_insert_id(); //get the assigned id for a nurse

$sql ="INSERT INTO Disease(Illness, Symptoms, Diagnosis, Treatment, PatientID)
   VALUES('$illness', '$symptoms', '$diagnosis', '$treatment', '$patient_id')";
mysql_query($sql,$con) or die('Error: ' . mysql_error());
echo "$patient_id"; mysql_insert_id(); //get the assigned id for a patient 

//use nurse_id and patient_id
$sql ="INSERT INTO Priority(NurseID, PatientID, Priority)
   VALUES('$nurse_ID', '$patient_id', '$priority')";
mysql_query($sql,$con) or die('Error: ' . mysql_error());
echo "$priority_id"; mysql_insert_id(); //get the assigned id for priority
echo "$patient_id"; mysql_insert_id(); //get the assigned id for a patient

$sql="INSERT INTO Patient(Forename, Surname, Gender, Date_Of_Birth, Address, Patient_History, Illness, Priority)
  VALUES     ('$patient_name', '$patient_lastname', '$gender', '$date', '$address', '$history', '$illness', '$priority')";
 mysql_query($sql,$con) or die('Error: ' . mysql_error());
 echo "$patient_id"; mysql_insert_id(); //get the assigned id for a patient

echo "1 record added";
 // close connection 
 mysql_close($con);
 ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:28:44+00:00Added an answer on June 18, 2026 at 5:28 am
    1. you need to use unique ids, names and lastname for different entities (nurse, patient, disease etc). And then use them appropriately in INSERT statements. See revised code below.
    2. select your db only once at the beginning of the script with mysql_select_db (if you planning to stick with mysql_*).
    3. Sanitize and validate input from the user before inserting it.
    4. Insert your records in correct (logical) order (nurse, patient, disease, priority).
    5. Now all of your ids come via POST. You might consider using id auto-reneration in mysql.
    6. You have a missing variable $priority_id. I’ve put it in the revised code assuming that you get it the same way via POST.
    7. Do proper error handling not just die().
    8. Better consider to switch to PDO or mysqli_* and use prepared statements.

    Revised code (updated):

    Assumption is that auto_increment is enabled for the id column of every table.

    $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error());
    mysql_select_db("a&e", $con) or or die('Could not select database.');
    
    //get NURSE values from form
    //We don't need to post an id for a Nurse since mysql will assign it for us
    //$nurse_id = $_POST['nurse_id'];
    $nurse_name = $_POST['nurse_name']; 
    $nurse_lastname = $_POST['nurse_lastname'];
    
    //get Disease values from form
    // We don't need to post an id for a Disease since mysql will assign it for us
    //$disease_id = $_POST['disease_id'];
    $symptoms = $_POST['symptoms'];
    $diagnosis = $_POST['diagnosis'];
    $treatment = $_POST['treatment'];
    
    //get Patient values from form
    //We don't need to post an id for a Patient since mysql will assign it for us
    //$patient_id = $_POST['patient_id'];
    $patient_name = $_POST['patient_name'];
    $patient_lastname = $_POST['patient_lastname'];
    $gender = $_POST['gender'];
    $dateOfBirth = $_POST['dateOfBirth'];
    $monthOfBirth = $_POST['monthOfBirth'];
    $yearOfBirth = $_POST['yearOfBirth'];
    $address = $_POST['address'];
    $history = $_POST['history'];
    $illness = $_POST['illness'];
    $priority = $_POST['priority'];
    
    //We don't need to post an id for a Priority entity since mysql will assign it for us
    //missing variable
    //$priority_id = $_POST['priority_id'];
    
    //Sanitize and validate your input here 
    // ...skipped
    // Validate
    $date = $dateOfBirth.'-'.$monthOfBirth.'-'.$yearOfBirth;
    
    //We don't provide an id for a Nurse since mysql will assign it for us
    $sql ="INSERT INTO Nurse(Forename, Surname)
           VALUES('$nurse_name', '$nurse_lastname')";
    mysql_query($sql,$con) or die('Error: ' . mysql_error());
    $nurse_id = mysql_insert_id(); //get the assigned id for a nurse
    
    //We don't provide an id for a Patient since mysql will assign it for us
    $sql="INSERT INTO Patient(Forename, Surname, Gender, Date_Of_Birth, Address, Patient_History, Illness, Priority)
          VALUES('$patient_name', '$patient_lastname', '$gender', '$date', '$address', '$history', '$illness', '$priority')";
    mysql_query($sql,$con) or die('Error: ' . mysql_error());
    $patient_id = mysql_insert_id(); //get the assigned id for a patient
    
    //We don't provide an id for a Disease since mysql will assign it for us
    $sql ="INSERT INTO Disease(Illness, Symptoms, Diagnosis, Treatment, PatientID)
           VALUES('$illness', '$symptoms', '$diagnosis', '$treatment', '$patient_id')";
    mysql_query($sql,$con) or die('Error: ' . mysql_error());
    
    //We don't provide an id for a Priority since mysql will assign it for us
    //But we use $nurse_id and $patient_id that we get earlier
    $sql ="INSERT INTO Priority(NurseID, PatientID, Priority)
           VALUES('$nurse_id', '$patient_id', '$priority')";
    mysql_query($sql,$con) or die('Error: ' . mysql_error());
    
    echo "1 record added";
    // close connection 
    mysql_close($con);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so basically i'm trying to submit a form with some javascript arrays. I
Okay I been trying to work this out but unable too. I have a
Okay, I'm trying to get ActionBarSherlock working, so I imported the library by: Creating
Okay, this may seem silly, but on an ASP.NET .ascx control, I'm trying to
Okay I'm trying to move from VB to C# with mixed success. I'm getting
Okay so, I'm working with CodeIgniter. posts.php is my view that displays all the
Okay so I have been trying to get into IoC lately. However, I keep
I'm trying to submit a simple jQuery ajax call but using the DELETE method
i am trying escape some data before it goes into my database, but i
Okay so what I'm trying to do is get the filename from OpenFileDialog/SaveFileDialog, only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.