A complex [for me] if / else statement

Greetings - So I have an issue with my form right now which can be found here: http://youawfulme.com/Form.html

If you look, you will see two expanding columns under Providers and References.

The HTML code for them to expand looks like this:

Next Provider

and the PHP code that handles their database storage looks like this:

// Insert Providers.. if(count($_POST['tfa_FirstName1']) > 1) {
	for($i = 0; $i < count($_POST['tfa_FirstName1']); $i++)
	{


		$tmpsql = "INSERT INTO tmpProviders (tmpId,FirstName,LastName,LicenseType,PrimarySpecialty,SecondarySpecialty,NYStateLicenseNum,DEANumber,NPINumber,EmailAddress,DaysPerWeek,PrimaryCareProv) VALUES ($oldid,'" . $_POST['tfa_FirstName1'][$i] . "'";


		$tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_LastName1'][$i]) . "'";
		$tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_LicenseType1'][$i]) . "'";
		$tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_PrimarySpecialty1'][$i]) . "'";
		$tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_SecondarySpecial'][$i]) . "'";
		$tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_NYStateLicenseNu1'][$i]) . "'";
		$tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_DEANumber1'][$i]) . "'";
		$tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_NPINumber1'][$i]) . "'";
		$tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_EmailAddress1'][$i]) . "'";
		$tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_DaysPerWeek1'][$i]) . "'";
		$tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d+/","\\1",$_POST['tfa_Ifthisindividual'][$i]) . "');";
	
  mysql_query($tmpsql);
}
   
}
else
{
   $tmpsql = "INSERT INTO tmpProviders (tmpId,FirstName,LastName,LicenseType,PrimarySpecialty,SecondarySpecialty,NYStateLicenseNum,DEANumber,NPINumber,EmailAddress,DaysPerWeek,PrimaryCareProv) VALUES ($oldid,'" . $_POST['tfa_FirstName1'] . "'";
  $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_LastName1']) . "'";
  $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_LicenseType1']) . "'";
  $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_PrimarySpecialty1']) . "'";
  $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d*/","\\1",$_POST['tfa_SecondarySpecial']) . "'";
  $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_NYStateLicenseNu1']) . "'";
  $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_DEANumber1']) . "'";
  $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_NPINumber1']) . "'";
  $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_EmailAddress1']) . "'";
  $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_/","",$_POST['tfa_DaysPerWeek1']) . "'";
  $tmpsql = $tmpsql . ",'" . preg_replace("/tfa_([a-zA-Z]+)\d+/","\\1",$_POST['tfa_Ifthisindividual']) . "');";


   mysql_query($tmpsql);

}


if(count($_POST['tfa_PracticeName']) > 1)
{</blockquote>

At this moment, when you fill out my form, all of the information saves to three separate tables. The Provider input goes into a temporary providers table, the Referrals to a temporary Referral , and the rest of the data to a temporary information table. Once the user submits the application, the temporary tables are cleared after having been moved to permanent tables (Still three tables)

My goal is for all of these values to save to one table, whether it be from three separate temps to one final or one temp to one final. My programmer was having trouble figuring it out and kind of left me on my own… I really need some help :wtf:

The Providers and Reference tables are done in such a way that if there are more than one entry, it will create a new row for each entry with a new ID number but the same “tempid” number, the latter matching the ID number in the main information table.

Can I have it such that PHP will check to see if the tempIDs match, and if they do, move the information into new columns on the same row? So that way, instead of having say 3 different IDs with one temp ID for three different providers… instead have that information all placed on one row, with one ID, and new columns?

In my head, I figured I would expand my table 5x. If I have five columns now, I will have 25 after. For each “Provider Name”, I will now have “Second Provider Name”, “Third Provider” name, etc… If the user only adds one provider, these won’t be used. If they had multiples, up to five, the info will be placed into these new columns.

I just can’t get this to work… When I expand the column and inspect the element in HTML, it says, for example, Provider[1] and Provider[2] … Incrementing in brackets for each addition. But if I try to, say

$SecondProviderName = $_POST['tfa_ProviderName[2]'];

… It simply doesn’t work.

Sorry for all this, I just need some help and so far you guys have been a great resource.

Here, this may be of help too…

This is one of the two expandable fields in question. So for this particular form, I am entering two referrals, hitting the next button once. So I will have referral 0 and referral 1.


In my Referrals table, this is my entry. The ID increments but the tempID remains the same showing that we are dealing with the same form/application. In the table including all of the other post data, minus providers, the ID would match the tempID here.

This format does not work for my mail merge operation down the line because that draws from column names. So say I have two fields in my contract fro Provider Name under referrals, I can’t use <> because they both share that column. I would instead want every additional entry to be placed in the same row with a unique column name.

Does this make more sense?

You can have 25 columns in your database table if you like, but common practice in this case is to have one table with just id, tmpId, and have another table with providers info. So that if you have more than 1 provider sibmitted in one request form, you can have unique id stored in “requests” table, while all the provides from this request will be saved in “providers” table… they will have their own id, but also have common request_id (referencing to the “requests” table).
Having data organized this way will let you search providers table easily. While in table with 5 x 5 fields, if you need to find provider by name, you will need to search by 5 fields (Provider Name 1, Provider Name 2, etc.).

In any case, to process submitted form, you need to use in PHP this syntax:
[php]$SecondProviderName = $_POST[‘tfa_ProviderName’][2];
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service