OK I see what you're doing and understand it 100%, however, the id is not being returned. All I get is XXXid=XXX123.
here is the entire code for this. It's not mine either I am just trying to make a couple of minor changes.
function InsertReportIntoDB($pirep_array) {
/* ************************************************************************************************
@InsertReportIntoDB
Receives a string array with FSAcars pireps and inserts summary into reports table
Inputs: string array
Outputs: 1 sucess, 0 error
************************************************************************************************ */
/* If this is the first chunk insert PIREP on database */
if ($pirep_array['more']=="0") {
/* connect to database */
include(MYSQL_CONNECT_INCLUDE);
/*
* Verify pilot identity (From VA Pilots table) */
$the_pilot = $pirep_array['pilot'];
// Section I am trying to edit starts here
//========================================
//========================================
//Suggested code here
// $tmp = "select id from pilots";
// $pID = $id;
$pID = 'id';
$nID = 'AN'.$pID;
$stmt = "select id from pilots where $nID = '$the_pilot'";
//Original Code here
// $stmt = "select id from pilots where pilot_num='$the_pilot'";
$result = mysql_query($stmt);
//End Section trying to edit
//========================================
//========================================
//Just a quick check for me
$pID1 = mysql_result($result,0,"id");
$nID1 = 'AN'.$pID1;
/* mysql error */
if (!$result) {
$fe = fopen (ERROR_LOG_PATH, "a");
fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] ".ERROR_IN_PILOT_QUERY." - Pilot ".$pirep_array['pilot']." - ".mysql_error()." SQL: ".$stmt."\n");
fclose($fe);
return 0;
}
if (mysql_num_rows($result) == 0) {
/* Pilot not found */
$fe = fopen (ERROR_LOG_PATH, "a");
fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] ".PILOT_NOT_FOUND." - Pilot ".$nID." - 2: ".$nID1."\n");
// fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] ".PILOT_NOT_FOUND." - Pilot ".$pirep_array['pilot']."\n");
fclose($fe);
return 0;
} else {
/* Pilot found */
$id = mysql_result($result,0,"id");
/* Insert info on reports table */
$values = $id.",'".$pirep_array['date']."','".$pirep_array['time']."','".$pirep_array['callsign']."','".$pirep_array['origin']."','".$pirep_array['dest']."','".$pirep_array['reg']."','".$pirep_array['equipment']."','".$pirep_array['duration']."',".$pirep_array['fuel'].",".$pirep_array['distance'].",'".$pirep_array['rep_url']."'";
$stmt = "INSERT INTO reports (id,date,time,callsign,origin_id,destination_id,registration,equipment,duration,fuel,distance,fsacars_rep_url) VALUES ($values)";
$result = mysql_query($stmt);
if (!$result) {
$fe = fopen (ERROR_LOG_PATH, "a");
fwrite($fe, "[ERROR ".date("d.m.y H:i:s")."] ".ERROR_INSERTING_PIREP." - Pilot ".$pirep_array['pilot']." - ".mysql_error()." SQL: ".$stmt."\n");
fclose($fe);
return 0;
}
/* Close the database connection */
mysql_close();
}
}
return 1;
}
function main() {
As you can see I also put a second $nID there called &nID1 to see if the id is returned after the query is called, still same though. I can't, for some reason, pull the id from the table.
I have also tried many variations to try and get this id to come up, some of them have been commented out, but no matter what I have tried, I still can't get it.
Cheers
Steph.