Jump to content

Help with submitting a pirep from $_POST Functions


Guest

Recommended Posts

Hey there,

My Friend and I created a java GUI application which reads our schedules database and lets the user search for a flight and gets the right data ready. You then click on 'Start Flight' and after you fly it, click on 'End Flight'. (Note that this is made for FlightGear Free and Open Source Flight Simulator) Then the application reads the flight time, fuel used and the route flown and posts the following variables to a temporary link (www.merlionvirtual.clubos.net/auto/scheduled.php)

Now, there's nothing in the php file, so what do I put there so it can submit the PIREP with the posted data?

pilotid

password

depicao

arricao

flightnum

aircraft

flighttime

route

fuel

Thanks a LOT for your help. :lol:

Link to comment
Share on other sites

Would this work? (The file is in the ACARS folder next to fspax.php)

 # Defining some string that we don't get/need from the APS
$comment .= 'Submitted by the Automatic PIREP System';
$code .= 'MIA'; # This must be changed for the VA using the APS

# Getting POST Data from the client and compiling it for submission
$data = array( 'pilotid'=>$_POST['pilotid'],
	'code'=>$code,
	'flightnum'=>$_POST['flightnum'],
	'depicao'=>$_POST['depicao'],
	'arricao'=>$_POST['arricao'],
	'aircraft'=>$_POST['aircraft'],
	'route'=>$_POST['route'],
	'flighttime'=>$_POST['flighttime'],
	'submitdate'=>'NOW()',
	'fuelused'=>$_POST['fuel'],
	'comment'=>$comment);

	$ret = ACARSData::FilePIREP($pilotid, $data);

The login is managed directly with the java client and about aircraft, does it have to be the number or the registration? If it's the number, the java sends the registration, how do I convert it?

Thanks!

Link to comment
Share on other sites

Hmm, I continued with the php too so I can also get to know a bit more about it. Here's what I came up with now, but there's an error.

First of all, here's the code :

<?php

$con = mysql_connect("localhost", "merlio2_merlion", "  ");
if(!$con)
    {
         die('Could not Connect! : ' . mysql_error());
    }

mysql_select_db("merlio2_merlion", $con);

$reg_sent = $_POST['aircraft'];
$flightnum = $_POST['flightnum'];

$aircraftdata = "SELECT id, maxpax FROM phpvms_aircraft WHERE registration=$reg_sent";

$aircraft = 'id';
$load = 'maxpax';

$scheduledata = "SELECT price, distance FROM phpvms_schedules WHERE flightnum=$flightnum";

$price = 'price';
$distance = 'distance';

$gross = $price * $load;
$pilotpay = $gross / 10;

$fuelprice = $_POST[fuel] * 5.1;

$revenue = $gross - $fuelprice;

$sql = "INSERT INTO phpvms_pireps (pilotid, code, flightnum, depicao, arricao, route, aircraft, flighttime, submitdate, fuelused, fuelunitcost, source, load, distance, gross, pilotpay, fuelprice, flighttype, revenue) VALUES ('$_POST[pilotid]', 'MIA', '$_POST[flightnum]', '$_POST[depicao]', '$_POST[arricao]', '$_POST[route]', '$aircraft', '$_POST[flighttime]', 'NOW()', '$_POST[fuel]', '5.1', 'VSA-APS', '$load', '$distance', '$gross', '$pilotpay', '$fuelprice', 'P', '$revenue')";


if (!mysql_query($sql,$con))
 {
 die('Error: ' . mysql_error());
 }
echo "PIREP Successfully submitted! Thank you for using Virtual Star Alliance's Automatic PIREP system";

mysql_close($con)
?> 

And here's the error :

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'load, distance, gross, pilotpay, fuelprice, flighttype, revenue) VALUES ('', 'MI' at line 1

Can someone please help me? Again... :D

Link to comment
Share on other sites

Hey,

Found the error by going through My MySQL textbook. :lol: Seems that "LOAD" is a reserved command so I can't use it directly. I've corrected that by using back quotations (`).

eg. using `load` instead of load.

Thanks anyway, and the time-stamp is also an error but I fixed that with date() function in php. For those (well, this is only for flightgear) interested, let me know and I'll paste the java GUI and the php source code up here. :P

Link to comment
Share on other sites

  • Administrators

Don't write directly to the database. You'll lose any data integrity, and you'll lose things in updates (like in the betas, a ton of code has changed in the pirep submission process). And all that financial code is changing/changed

You need to use the ACARSData::filePIREP function. Read through here:

http://forum.phpvms....html?category=6

Looks through this code:

https://github.com/n...sacars.php#L386

And look how each variable is formatted so then it's submitted

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...