UBB.Dev
Posted By: AKD96 Entering data into multiple tables using one form - 05/19/2004 11:27 PM
I know there has to be a shorter way of doing this than what I've come up with.

I am creating a score entry form for a fantasy league for drum corps. Corps are given scores on different aspects (captions) of their show which are calculated together to get a final score.

I am trying to create a form where someone can enter the names of the competing corps at a certain competition along with all of their caption scores, which are then written to the database. Here is an example of what I have come up with so far...
[]http://www.drumlines.org/upload/captions.gif[/]

I have created a table for each corps that contains the captions scores and a competition id for the primary. I want to be able to enter all of the corps' scores on the same form to submit it and have everything be written to each corps' respective database. To accomplish having two entries I have appended "2" to the end of the variables and created a second query.

There has to be an easier way to do this. Does anyone out there understand my ramblings?

This should give you an idea of how I'm doing it...
Code
 <br />// ------------------------------------------- <br />// Add the competition results to the database <br />   $query = " <br />	INSERT INTO fdc_$corps (comp_id,gemus,gevis,musbras,musperc,musens,visperf,visguard,visens,penalty,finalscore) <br />	VALUES ('$competition','$gemus','$gevis','$musbras','$musperc','$musens','$visperf','$visguard','$visens','$penalty','$finalscore') <br />   "; <br />   $dbh -> do_query($query); <br /> <br />   $query = " <br />	INSERT INTO fdc_$corps2 (comp_id,gemus,gevis,musbras,musperc,musens,visperf,visguard,visens,penalty,finalscore) <br />	VALUES ('$competition','$gemus2','$gevis2','$musbras2','$musperc2','$musens2','$visperf2','$visguard2','$visens2','$penalty2','$finalscore2') <br />   "; <br />   $dbh -> do_query($query); <br />
Unfortunately, you can only update one table at a time. You can read from multiple tables with a join, but I'm not aware of a way to update two different database tables at once.


Thanks for clarifying.
© UBB.Developers