Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5697 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted (edited)

Is it possible to create a new related record through PHP without using a portal? For example, I have an existing FMP db with a Patients table and a Procedures table. A user can find an existing patient in the Patients layout and press a corresponding button that runs a script in order to create a new procedure for that patient. This script simply sets a variable to the current patient's primary key ID, then switches to the Procedures layout and sets the procedure's foreign key ID to the variable that was just set. This, in essence, creates a new record in the Procedures layout/table which is related to a specific patient.

I haven't been able to figure out how to do this using PHP. Am I going about it all wrong? Is it better/easier to just create a portal in the patient's detail page and add a new portal record?

Thank in advance for your help.

Edited by Guest
Posted

I figured it out! For anyone who is a newbie and/or is having trouble understanding "new queries", here is the solution:

  • First of all, a new query actually creates a new record even if your response page has an error. I was unaware of this until I noticed how many new entries were in my database.
  • In my search results page, I added a column in which I created a form with no input fields; only a hidden field. I labeled the form button "New Procedure". The hidden field value was set to the record's primary key ID.
  • In another page I created a record set which "found" the one ID I submitted in the previous page. I then created a blank form which listed the fields which were necessary to populate a new charge. I created another hidden field within this new form that contained the primary key (kp_ID) I previously submitted. However, I gave this hidden field the name "kf_ID". This "name" is simply the name of the variable PHP will use to capture the value which is still the primary key data. So, ultimately this form is going to send data for a new record, and it will populate the foreign key field with the existing primary key (along with the relevant new record data).
  • On a "new procedure confirmation" page, I created a New Query which was looking for the variable names which I specified on the previous page. It doesn't matter if your new query is going to be populating a different layout or table, as long as the names of the variables you submitted in the previous form match the names of the variables that the new query is looking for, it will populate the fields correctly.
  • Therefore, I ended up with a new procedure record which contained the correct foreign key and was correctly related to the proper patient.

I hope that helps someone. It took me a while to get the basic concept that the forms submit variables which the queries use to set fields in the new record; regardless of which layouts or tables you were originally in. The nature of the variable is to hold whatever data you need for the moment, and use it however you want when the time comes.

Posted

Nice Job working through it. There is one minor problem with this that should be clarified to save a bit of confusion down the road.

This "name" is simply the name of the variable PHP will use to capture the value which is still the primary key data. So, ultimately this form is going to send data for a new record, and it will populate the foreign key field with the existing primary key (along with the relevant new record data).

This is dependent on having php's register_globals variable set to "On". In current versions it is set to "Off" by default and will eventually be removed entirely.

If register_globals is turned off you will need to use the $_GET, $_POST,or $_REQUEST arrays to access your submitted form variables

e.g.


















<?php

/* On processGet.php */

echo $_GET["hiddenVar"]; /*1*/

echo $_POST["hiddenVar"];/**/

echo $_REQUEST["hiddenVar"]; /*1*/



/* On processPost.php */

echo $_GET["hiddenVar"]; /**/

echo $_POST["hiddenVar"];/*2*/

echo $_REQUEST["hiddenVar"]; /*2*/



?>

This topic is 5697 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.