This topic is locked

Insert Record into Another Table...

12/7/2007 12:26:12 AM
PHPRunner General questions
R
run4sbc author

I got the insert record into another table to work the way I wanted. (Thanks for the tip Alexey, I used the insert instead of save new data and it worked great)
Now I am trying to add multiple records to another table from one add page. I can get the same record added twice, but cant get extra field to add correctly.
For example I have fields in my "Master" table

EventCode EntryMark

EventCode2 EntryMark2

EventCode3 EntryMark3

EventCode4 EntryMark4
I want to have 4 events that add that info into an "Individual" table. All going into fields called

EventCode EntryMark
I dont think it is letting EventCode2 add into EventCode of the other table. I just wanted to confirm that this is my problem. Any help would be greatly appreciated!
This Code Works

global $conn;

$strSQLInsert = "insert into _ArkansasInviteIndividual (EventType, LastName, FirstName, Gender, TeamCode, TeamName, SchoolYear, EventCode, EntryMark, EventMeasure, RegNum, TimeModified) values ('" . $values["EventType"]. "','" . $values["LastName"]. "','" . $values["FirstName"]. "','" . $values["Gender"]. "','" . $values["TeamCode"]. "','" . $values["TeamName"]. "','" . $values["SchoolYear"]. "','" . $values["EventCode"]. "','" . $values["EntryMark"]. "','" . $values["EventMeasure"]. "','" . $values["RegNum"]. "','" . $values["TimeModified"] . "')";

db_exec($strSQLInsert,$conn);
This Code Doesnt Work

global $conn;

$strSQLInsert = "insert into _ArkansasInviteIndividual (EventType, LastName, FirstName, Gender, TeamCode, TeamName, SchoolYear, EventCode2, EntryMark2, EventMeasure, RegNum, TimeModified) values ('" . $values["EventType"]. "','" . $values["LastName"]. "','" . $values["FirstName"]. "','" . $values["Gender"]. "','" . $values["TeamCode"]. "','" . $values["TeamName"]. "','" . $values["SchoolYear"]. "','" . $values["EventCode"]. "','" . $values["EntryMark"]. "','" . $values["EventMeasure"]. "','" . $values["RegNum"]. "','" . $values["TimeModified"] . "')";

db_exec($strSQLInsert,$conn);
If anyone has any ideas let me know. I want to have 4 seperate insert scripts to add 4 records into the _ArkansasInviteIndividual table. And putting the data all in the same fields in that table.
Thanks!

Alexey admin 12/7/2007

Hi,
you use INSERT statement improperly.

Here is the link where you can learn its syntax.

http://www.webcheatsheet.com/sql/interacti.../sql_insert.php
your statement should look like this:

$strSQLInsert = "insert into _ArkansasInviteIndividual (..., EventCode, EntryMark, ..) values (.... $values["EventCode2"]. "','" . $values["EntryMark2"]. ...)";

R
run4sbc author 12/7/2007

Alexey,
I realized at about 4am that I was changing the tables label instead of the variable.
I dont really understand what you mean by improperly because this code worked perfectly.
// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair
//** Insert a record into another table ****

global $conn;

$strSQLInsert = "insert into _ArkansasInviteIndividual (EventType, LastName, FirstName, Gender, TeamCode, TeamName, SchoolYear, EventCode, EntryMark, EventMeasure, RegNum, TimeModified) values ('" . $values["EventType"]. "','" . $values["LastName"]. "','" . $values["FirstName"]. "','" . $values["Gender"]. "','" . $values["TeamCode"]. "','" . $values["TeamName"]. "','" . $values["SchoolYear"]. "','" . $values["EventCode"]. "','" . $values["EntryMark"]. "','" . $values["EventMeasure"]. "','" . $values["RegNum"]. "','" . $values["TimeModified"] . "')";

db_exec($strSQLInsert,$conn);
global $conn;

$strSQLInsert = "insert into _ArkansasInviteIndividual (EventType, LastName, FirstName, Gender, TeamCode, TeamName, SchoolYear, EventCode, EntryMark, EventMeasure, RegNum, TimeModified) values ('" . $values["EventType"]. "','" . $values["LastName"]. "','" . $values["FirstName"]. "','" . $values["Gender"]. "','" . $values["TeamCode"]. "','" . $values["TeamName"]. "','" . $values["SchoolYear"]. "','" . $values["EventCode2"]. "','" . $values["EntryMark2"]. "','" . $values["EventMeasure"]. "','" . $values["RegNum"]. "','" . $values["TimeModified"] . "')";

db_exec($strSQLInsert,$conn);
global $conn;

$strSQLInsert = "insert into _ArkansasInviteIndividual (EventType, LastName, FirstName, Gender, TeamCode, TeamName, SchoolYear, EventCode, EntryMark, EventMeasure, RegNum, TimeModified) values ('" . $values["EventType"]. "','" . $values["LastName"]. "','" . $values["FirstName"]. "','" . $values["Gender"]. "','" . $values["TeamCode"]. "','" . $values["TeamName"]. "','" . $values["SchoolYear"]. "','" . $values["EventCode3"]. "','" . $values["EntryMark3"]. "','" . $values["EventMeasure"]. "','" . $values["RegNum"]. "','" . $values["TimeModified"] . "')";

db_exec($strSQLInsert,$conn);
global $conn;

$strSQLInsert = "insert into _ArkansasInviteIndividual (EventType, LastName, FirstName, Gender, TeamCode, TeamName, SchoolYear, EventCode, EntryMark, EventMeasure, RegNum, TimeModified) values ('" . $values["EventType"]. "','" . $values["LastName"]. "','" . $values["FirstName"]. "','" . $values["Gender"]. "','" . $values["TeamCode"]. "','" . $values["TeamName"]. "','" . $values["SchoolYear"]. "','" . $values["EventCode4"]. "','" . $values["EntryMark4"]. "','" . $values["EventMeasure"]. "','" . $values["RegNum"]. "','" . $values["TimeModified"] . "')";

db_exec($strSQLInsert,$conn);
return true;
// return true if you like to proceed with adding new record

// return false otherwise