I have a script written by another person. This script is designed to receive a datastream from a program and insert the values from that datastream into a table on my database. What I want to do is to also take some of the variables from that data and insert or update another table on the databse.
Here is the first script:
<?php
function GetNewIDPIREP($FlightNumber)
{
return date("dmYHis").$FlightNumber;
}
if (!isset($_REQUEST["DATA2"])) die("Invalid PIREP data (no data transmitted).");
/* ### Changed in 2.6 ### */
$PIREP =str_replace("\'", "''", " ".$_REQUEST["DATA2"]);
//Get Flight Data - <FLIGHTDATA>
$i = 0;
$i = strpos($PIREP, "<FLIGHTDATA>", 0);
if ($i != false) {
$i = $i + strlen("<FLIGHTDATA>");
$j = $i;
$j = strpos($PIREP, "</FLIGHTDATA>", $j);
if ($j != false) {
$FlightData = trim(substr($PIREP, $i, $j - $i));
}
else {
die("Invalid PIREP data (end tag FLIGHTDATA is missing).");
}
}
else {
die("Invalid PIREP data (tag FLIGHTDATA is missing)."." ".$i);
}
$FlightData = str_replace("\r", "\n", $FlightData);
$FlightData = str_replace("\n", "", $FlightData);
//Get Flight Plan - <FLIGHTPLAN>
$i = 0;
$i = strpos($PIREP, "<FLIGHTPLAN>", 0);
if ($i != false) {
$i = $i + strlen("<FLIGHTPLAN>");
$j = $i;
$j = strpos($PIREP, "</FLIGHTPLAN>", $j);
if ($j != false) {
$FlightPlan = trim(substr($PIREP, $i, $j - $i));
}
else {
die("Invalid PIREP data (end tag FLIGHTPLAN is missing).");
}
}
else {
die("Invalid PIREP data (tag FLIGHTPLAN is missing)."." ".$i);
}
//Get Comment - <COMMENT>
$i = 0;
$i = strpos($PIREP, "<COMMENT>", 0);
if ($i != false) {
$i = $i + strlen("<COMMENT>");
$j = $i;
$j = strpos($PIREP, "</COMMENT>", $j);
if ($j != false) {
$Comment = trim(substr($PIREP, $i, $j - $i));
}
else {
die("Invalid PIREP data (end tag COMMENT is missing).");
}
}
else {
die("Invalid PIREP data (tag COMMENT is missing)."." ".$i);
}
//Get Flight Critique - <FLIGHTCRITIQUE>
$i = 0;
$i = strpos($PIREP, "<FLIGHTCRITIQUE>", 0);
if ($i != false) {
$i = $i + strlen("<FLIGHTCRITIQUE>");
$j = $i;
$j = strpos($PIREP, "</FLIGHTCRITIQUE>", $j);
if ($j != false) {
$FlightCritique = trim(substr($PIREP, $i, $j - $i));
}
else {
die("Invalid PIREP data (end tag FLIGHTCRITIQUE is missing).");
}
}
else {
die("Invalid PIREP data (tag FLIGHTCRITIQUE is missing)."." ".$i);
}
//Get Flight Maps - <FLIGHTMAPS>
$i = 0;
$i = strpos($PIREP, "<FLIGHTMAPS>", 0);
if ($i != false) {
$i = $i + strlen("<FLIGHTMAPS>");
$j = $i;
$j = strpos($PIREP, "</FLIGHTMAPS>", $j);
if ($j != false) {
$FlightMaps = trim(substr($PIREP, $i, $j - $i));
}
else {
die("Invalid PIREP data (end tag FLIGHTMAPS is missing).");
}
}
else {
die("Invalid PIREP data (tag FLIGHTMAPS is missing)."." ".$i);
}
$FlightMaps = str_replace("\r", "\n", $FlightMaps);
$FlightMaps = str_replace("\n", "", $FlightMaps);
//Analyze Flight Data
$arData = split("~", $FlightData);
if (count($arData) < 38) {
die ("There are fields missing in the Flight Data (".(count($arData) + 1)."/39)");
}
//Analyze Flight Maps Data
$arFlightMaps = split("~", $FlightMaps);
if (count($arFlightMaps) < 3) {
die ("There are fields missing in the Flight Maps Data (".(count($arFlightMaps) + 1)."/4)");
}
/* Connect to Database */
include("dbinfo.inc.php");
$link = mysql_connect(localhost,$username,$password) or die("SQL Server connection failed.");
mysql_select_db("margari_mountainexpress") or die("Database connection failed.");
$query = "INSERT INTO pirep (IDPIREP, CreatedOn, IDPilot, PilotName, AircraftTitle, AircraftType, TailNumber, Airline, FlightNumber, FlightLevel, FlightType, Passenger, Cargo, ZFW, OriginAirport, OriginGate, OriginRunway, OriginTA, DestinationAirport, DestinationGate, DestinationRunway, DestinationTA, AlternateAirport, SID, STAR, DistanceFlight, DistanceRoute, OUTTime, OFFTime, ONTime, INTime, DayFlightTime, NightFlightTime, BlockTime, FlightTime, BlockFuel, FlightFuel, TakeoffIAS, LandingIAS, LandingVS, FlightScore, FlightMapJPG, FlightMapWeatherJPG, FlightMapTaxiOutJPG, FlightMapTaxiInJPG, FlightPlan, FlightCritique, Comment) VALUES (";
//PilotID|PilotName|AircraftTitle|AircraftType|AircraftTailNumber|AircraftAirline|FlightNumber|FlightLevel|FlightType
// 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
//Passenger|Cargo|ZFW|OriginICAO|OriginGate|OriginRunway|OriginTransitionAltitude|DestinationICAO
// 9 | 10 | 11| 12 | 13 | 14 | 15 | 16
//DestinationGate|DestinationRunway|DestinationTransitionAltitude|AlternateICAO|SID|STAR|FlightDistance|RouteDistance
// 17 | 18 | 19 | 20 | 21| 22 | 23 | 24
//OUTTime|OFFTime|ONTime|INTime|DayFlightTime|NightFlightTime|BlockTime|FlightTime|BlockFuel|FlightFuel|TOIAS|LAIAS|ONVS|FlightScore
// 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38
/* ### Changed v2.6 ### */
if (strlen(trim($arData[6])) != 0) {
$IDPIREP = GetNewIDPIREP(trim($arData[6]));
}
else {
$IDPIREP = GetNewIDPIREP(trim($arData[0]));
}
$query = $query."'".$IDPIREP."', ";
$query = $query.date("YmdHis", time()).", ";
$query = $query."'".trim($arData[0])."', ";
$query = $query."'".trim($arData[1])."', ";
$query = $query."'".trim($arData[2])."', ";
$query = $query."'".trim($arData[3])."', ";
$query = $query."'".trim($arData[4])."', ";
$query = $query."'".trim($arData[5])."', ";
/* ### Changed v2.6 ### */
if (strlen(trim($arData[6])) != 0) {
$query = $query."'".trim($arData[6])."', ";
}
else {
$query = $query."'".$IDPIREP."', ";
}
$query = $query."'".trim($arData[7])."', ";
$query = $query."'".trim($arData[8])."', ";
$query = $query."'".trim($arData[9])."', ";
$query = $query."'".trim($arData[10])."', ";
$query = $query."'".trim($arData[11])."', ";
$query = $query."'".trim($arData[12])."', ";
$query = $query."'".trim($arData[13])."', ";
$query = $query."'".trim($arData[14])."', ";
$query = $query."'".trim($arData[15])."', ";
$query = $query."'".trim($arData[16])."', ";
$query = $query."'".trim($arData[17])."', ";
$query = $query."'".trim($arData[18])."', ";
$query = $query."'".trim($arData[19])."', ";
$query = $query."'".trim($arData[20])."', ";
$query = $query."'".trim($arData[21])."', ";
$query = $query."'".trim($arData[22])."', ";
$query = $query."'".trim($arData[23])."', ";
$query = $query."'".trim($arData[24])."', ";
$query = $query."'".trim($arData[25])."', ";
$query = $query."'".trim($arData[26])."', ";
$query = $query."'".trim($arData[27])."', ";
$query = $query."'".trim($arData[28])."', ";
$query = $query."'".trim($arData[29])."', ";
$query = $query."'".trim($arData[30])."', ";
$query = $query."'".trim($arData[31])."', ";
$query = $query."'".trim($arData[32])."', ";
$query = $query."'".trim($arData[33])."', ";
$query = $query."'".trim($arData[34])."', ";
$query = $query."'".trim($arData[35])."', ";
$query = $query."'".trim($arData[36])."', ";
$query = $query."'".trim($arData[37])."', ";
$query = $query."'".trim($arData[38])."', ";
$query = $query."'".trim($arFlightMaps[0])."', ";
$query = $query."'".trim($arFlightMaps[1])."', ";
$query = $query."'".trim($arFlightMaps[2])."', ";
$query = $query."'".trim($arFlightMaps[3])."', ";
$query = $query."'".$FlightPlan."', ";
$query = $query."'".$FlightCritique."', ";
$query = $query."'".$Comment."'";
$query = $query.");";
// Execute SQL query
$result = mysql_query($query) or die("SQL query failed.");
print "PIREP successfully transmitted.<br><br>\r\n";
print "Visit the <a href=\"http://www.mountainexpress.margaritaair.com/FSFK/PIREPDetails.php?ID=".$IDPIREP."\">PIREP Details</a> page to review your flight.";
// Close connection
mysql_close($link);
?>
My question is...would it be better to run another query to INSERT the variables into another table, or can I just do an UPDATE to that table, or does it matter?
Thanks