This topic is locked

Inserting data from one database table into another database table based on field value

3/6/2022 4:34:54 PM
PHPRunner General questions
D
Dynamiccomp author

I have a page where I want to insert all data rows from a different database table, if the field value entered, matches the value in the other database table, and I cannot seem to get it to work.
The current database is my_eventing, and the table name is 'online entries' and the database and table name I want it to compare to is 'my_events' and table name is: 'Event Packet'

Both databases use the same username and password, so I figured I might be able to get away with not passing that info, but maybe i was wrong, here is the code that I was trying:

DB::SetConnection("my_events" , 'Event Packet');

$soringdata = array();
$scoringkeyvalues = array();
$scoringdata["Number"] = $values['Number'];
$scoringdata["Rider Name"] = $values['Rider Name'];
$scoringdata["Horse Name"] = $values['Horse Name'];
$scoringdata["Division Name"] = $values['Division Name'];
$scoringdata["Level"] = $values['Level'];
$scoringdata["Division Type"] = $values['Division Type'];
$scoringdata["Show Type"] = $values['Show Type'];
$scoringdata["Dressage Test"] = $values['Dressage Test'];
$scoringkeyvalues["Number"] = $values['Number'];

if ($values['Event ID'] = $values['Event ID']){

DB::SetConnection("");
DB::Insert("Scoring", $scoringdata, $scoringkeyvalues );
}

return true;

the syntax checks out ok, and the page that I have to enter the event ID to check the external database table, doesn't give me an error, however the data doesn't get inserted, and without an error, not sure what the issue is.

Any ideas to help?

Sergey Kornilov admin 3/9/2022

There are numerous errors in this code. First, you changing the current database connection and not doing anything with it, changing it back to default connection before you execute any queries. Just doesn't make any sense.

Second, you are confusing assignment operator = with comparisson operator ==