Jump to content

Having a nightmare with an update query


nexissair

Recommended Posts

Afternoon everyone

I'm currently building a module for my site which I plan to share on here for everyone to use if they want, it allows you to add extra information to an aircraft that can then be shown on a nice shiney fleet page, I am a bit stuck though, whilst I can pull the aircraft, add extra information to them and display it all on the fleet page with no problems, I just cannot for the life of me get it to update existing added extra data, I've been staring at this for four days without success, the query works when run direct in SQL command line, I've tried absolutley everything but clearly I've missed something that I can't spot, Please please please can some one look over what I've done and let me know what I've missed because I can't find my error and its driving me nuts now, I so close to having this done but its vital that people have the ability to update what they've added. The code is below.

Core Class:

<?php
/**
* Karl Sawdy
*/

class FleetInfoData extends CodonData
{
//Public Functions - Fleet Page

//Get enabled ICAO's

public static function getAllicao()
{
$sql = 'SELECT DISTINCT icao, fullname FROM '.TABLE_PREFIX.'aircraft
WHERE enabled=1 ORDER BY `icao` ASC';

return DB::get_results($sql);
}


// Get all of the enabledd aircraft

public static function getAllAircraft()
{
$sql = "SELECT a.* FROM ".TABLE_PREFIX."aircraft a
WHERE enabled=1 ORDER BY a.registration";

return DB::get_results($sql);
}
//End Public Functions - Fleet Page




//Admin Functions

//Get All Aircraft Added
public static function getEveryAircraft()
{
$sql = "SELECT a.* FROM ".TABLE_PREFIX."aircraft a
ORDER BY a.registration";

return DB::get_results($sql);
}

//Get Aircraft with Added Details for Main Page
public function getAcDetails()
{
 $query = "SELECT a.*, e.* FROM phpvms_aircraft_details as e
LEFT JOIN ".TABLE_PREFIX."aircraft AS a ON a.id = e.aircraftid
ORDER BY a.icao ASC";
 return DB::get_results($query);
}


//Get a Specific Aircraft to Add Details to
public static function getAircraftInfo($id)
{
$id = DB::escape($id);

return DB::get_row('SELECT * FROM '.TABLE_PREFIX.'aircraft
 WHERE `id`='.$id);
}

//Add New Details to Existing Aircraft
public function save_new_details($aircraftid, $detregistration, $wingspan, $length, $height, $cruisemach, $ceiling, $engines, $base, $department, $status, $comments) {
 $query = "INSERT INTO phpvms_aircraft_details (aircraftid, detregistration, wingspan, length, height, cruisemach, ceiling, engines, base, department, status, comments )
				 VALUES('$aircraftid', '$detregistration', '$wingspan', '$length', '$height', '$cruisemach', '$ceiling', '$engines', '$base', '$department', '$status', '$comments')";
 DB::query($query);
}
// End Adding Details to Existing Aircraft

//Get a Specific Aircraft with Existing Details to Edit
public static function getAircraftEdit($id)
{
$id = DB::escape($id);

return DB::get_row('SELECT a.*,e.* FROM phpvms_aircraft_details AS e
LEFT JOIN phpvms_aircraft AS a ON a.id = e.aircraftid
 WHERE `aircraftid`='.$id);

}

//Edit Existing Details on Existing Aircraft
public function update_details($wingspan, $length, $height, $cruisemach, $ceiling, $engines, $base, $department, $status, $comments, $detid) {
 $query = "UPDATE phpvms_aircraft_details SET
wingspan='$wingspan'
length='$length'
height='$height'
cruisemach='$cruisemach'
ceiling='$ceiling'
engines='$engines'
base='$base'
department='$department'
status='$status'
comments='$comments'
WHERE detid='$detid'";
 DB::query($query);
}
}

Admin Module:

<?php

class FleetInfo extends CodonModule {

public function HTMLHead()
{
 $this->set('sidebar', 'fleetinfo/fleetinfo_sidebar.tpl');
}
public function NavBar()
{
 echo '<li><a href="'.SITE_URL.'/admin/index.php/FleetInfo">Additional Aircraft Info</a></li>';
}
public function index() {

$this->set('info', FleetInfoData::getAcDetails());
	 $this->show('fleetinfo/fleetinfo_index.tpl');
}

//Edit Existing Aircraft - Pages

//See All Existing Aircraft
public function SeeAllAddedAircraft()
{
$this->set('allaircraft', FleetInfoData::getEveryAircraft());
$this->render('fleetinfo/all_aircraftlist.tpl');
}

//Select The Existing Aircraft to Add Details to and show Add Details Page
public function SelectAircraft()
{
$id = $this->get->id;
$this->set('action', 'adddetails');
$this->set('allranks', RanksData::getAllRanks());
$this->set('aircraft', OperationsData::GetAircraftInfo($id));

$this->render('fleetinfo/fleetinfo_adddetails.tpl');
}

//Add Details 'action'
public function adddetails()
{
 $details = array();
 $details['aircraftid'] = DB::escape($this->post->aircraftid);
 $details['detregistration'] = DB::escape($this->post->detregistration);
 $details['wingspan'] = DB::escape($this->post->wingspan);
 $details['length'] = DB::escape($this->post->length);
 $details['height'] = DB::escape($this->post->height);
 $details['cruisemach'] = DB::escape($this->post->cruisemach);
 $details['ceiling'] = DB::escape($this->post->ceiling);
 $details['engines'] = DB::escape($this->post->engines);
 $details['base'] = DB::escape($this->post->base);
 $details['department'] = DB::escape($this->post->department);
 $details['status'] = DB::escape($this->post->status);
 $details['comments'] = DB::escape($this->post->comments);
$details['fullname'] = DB::escape($this->post->fullname);

 FleetInfoData::save_new_details($details['aircraftid'],
							 $details['detregistration'],
							 $details['wingspan'],
							 $details['length'],
							 $details['height'],
							 $details['cruisemach'],
							 $details['ceiling'],
							 $details['engines'],
							 $details['base'],
							 $details['department'],
	 $details['status'],
							 $details['comments']);
//Go to Admin Index page After Saving
$this->set('info', FleetInfoData::getAcDetails());
 $this->show('fleetinfo/fleetinfo_index.tpl');

//Add Successful Save info to user log
LogData::addLog(Auth::$userinfo->pilotid, 'Added Details To Aircraft "'.$this->post->fullname.' Registration '.$this->post->registration.'"');
}
//END Adding Details to Existing Aircraft






//Select The Existing Aircraft to Edit Details of and show Edit Details Page
public function EditAircaftDetails($id)
{
$this->set('action', 'save_edit_details');

$this->set('details',FleetInfoData::GetAircraftEdit($id));
$this->set('allranks', RanksData::getAllRanks());

$this->render('fleetinfo/fleetinfo_editdetail.tpl');
}

//Save Edited Details 'action'
public function save_edit_details()
{
 $ac = array();
 $ac['wingspan'] = DB::escape($this->post->wingspan);
 $ac['length'] = DB::escape($this->post->length);
 $ac['height'] = DB::escape($this->post->height);
 $ac['cruisemach'] = DB::escape($this->post->cruisemach);
 $ac['ceiling'] = DB::escape($this->post->ceiling);
 $ac['engines'] = DB::escape($this->post->engines);
 $ac['base'] = DB::escape($this->post->base);
 $ac['department'] = DB::escape($this->post->department);
 $ac['status'] = DB::escape($this->post->status);
 $ac['comments'] = DB::escape($this->post->comments);
$ac['detregistration'] = DB::escape($this->post->detregistration);
$ac['detid'] = DB::escape($this->post->detid);
$ac['fullname'] = DB::escape($this->post->fullname);

 FleetInfoData::update_details($ac['wingspan'],
								 $ac['length'],
								 $ac['height'],
								 $ac['cruisemach'],
								 $ac['ceiling'],
								 $ac['engines'],
								 $ac['base'],
								 $ac['department'],
	 $ac['status'],
								 $ac['comments'],
	 $ac['detregistration'],
	 $ac['detid']);

//Show Successful Update Message to User and index page
$this->set('message', 'The Aircraft "'.$this->post->fullname.' '.$this->post->detregistration.'" has been successfully Updated');
$this->render('core_success.tpl');
$this->set('info', FleetInfoData::getAcDetails());
 $this->show('fleetinfo/fleetinfo_index.tpl');

//Add Successful Update info to user log
LogData::addLog(Auth::$userinfo->pilotid, 'Edited Aircraft "'.$this->post->fullname.' '.$this->post->detregistration.'"');
}
}

Edit Details TPL

<h4>Existing Aircraft Details</h4>
<hr>

<form action="<?php echo adminurl('/FleetInfo/'.$action.'');?>" method="post">
<table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<td width="15%">Database ID Number</td>
<td><?php echo $details->id; ?></td>
</tr>
<tr>
<td width="15%">Aircraft ICAO</td>
<td><?php echo $details->icao; ?></td>
</tr>
<tr>
<td>Aircraft Name / Type</td>
<td><?php echo $details->name; ?></td>
</tr>
<tr>
<td>Full Name</td>
<td><?php echo $details->fullname; ?></td>
</tr>
<tr>
<td>Aircraft Registration</td>
<td><?php echo $details->registration; ?></td>
</tr>
<tr>
<td>Max Pax</td>
<td><?php echo $details->maxpax; ?> PAX</td>
</tr>
<tr>
<td>Max Cargo</td>
<td><?php echo $details->maxcargo; ?> lbs</td>
</tr>
<tr>
<td>Range</td>
<td><?php echo $details->range; ?> nM</td>
</tr>
<tr>
<td>weight</td>
<td><?php echo $details->weight; ?> lbs</td>
</tr>
<tr>
<td>Cruise Speed Kts</td>
<td><?php echo $details->cruise; ?> kts</td>
</tr>
<tr>
<td>Minimum Rank to Fly This Aircraft</td>
<td><?php
foreach($allranks as $rank)

if($details->minrank == $rank->rankid)

echo $rank->rank;


?></td>
</tr>
<tr>	
 <?php
if($details->enabled == 1)
{
echo '<td colspan="2" bgcolor="#00FF00" align="center"><strong>Aircraft Active - Can Be Flown Now</strong></td>';
}
else echo '<td colspan="2" bgcolor="#FF0000" align="center"><strong>Aircraft Not Active - Cannot Be Flown By Pilots</strong></td>'; ?>
</tr>
<tr>
 <td colspan="2">
 <hr>
 <h4>Update Additional Aircraft Details</h4>
 <hr>
 </td>
 </tr>
<tr>
 <td>Wingspan</td>
 <td><input type="text" name="wingspan" value="<?php echo $details->wingspan;?>" /> ft</td>
</tr>
<tr>
 <td>Length</td>
 <td><input type="text" name="length" value="<?php echo $details->length;?>" /> ft</td>
</tr>
<tr>
 <td>Height</td>
 <td><input type="text" name="height" value="<?php echo $details->height;?>" /> ft</td>
</tr>
<tr>
 <td>Cruise Mach</td>
 <td><input type="text" name="cruisemach" value="<?php echo $details->cruisemach;?>" /> mach</td>
</tr>
<tr>
 <td>Ceiling</td>
 <td><input type="text" name="ceiling" value="<?php echo $details->ceiling;?>" /> ft</td>
</tr>
<tr>
 <td>Engines</td>
 <td><input type="text" name="engines" style="width: 40%;" value="<?php echo $details->engines;?>" /></td>
</tr>
<tr>
 <td>Base</td>
 <td><select name="base"><option value="<?php echo $details->base;?>"></option>
	 <option value="To Be Confirmed">To Be Confirmed</option>
				 <option value="EGSS">EGSS</option>
				 <option value="PANC">PANC</option>
				 <option value="KMIA">KMIA</option>
			 </select> Currently Set To: <strong><?php echo $details->base;?></strong></td>
</tr>
<tr>
 <td>Department</td>
 <td><select name="department"><option value="<?php echo $details->department;?>"></option>
 <option value="To Be Confirmed">To Be Confirmed</option>
				 <option value="Schedules">Schedules</option>
				 <option value="Charters">Charters</option>
				 <option value="Cargo">Cargo</option>
				 <option value="Executive Charters">Executive Charters</option>
				 <option value="Vintage">Vintage</option>
				 <option value="Private">Private</option>
			 </select> Currently Set To: <strong><?php echo $details->department;?></strong></td>
</tr>
<tr>
 <td>Status</td>
 <td><select name="status"><option value="<?php echo $details->status;?>"></option>
	 <option value="Active">Active</option>
				 <option value="On Order">On Order</option>
				 <option value="In Storage">In Storage</option>
				 <option value="Retired">Retired</option>
				 <option value="External Contract">External Contract</option>
				 <option value="Leased">Leased</option>
				 <option value="Re-Fit">Re-Fit</option>
				 <option value="Sold">Sold</option>
				 <option value="Scrapped">Scrapped</option>
			 </select> Currently Set To: <strong><?php echo $details->status;?></strong></td>
</tr>
<tr>
 <td>Notes</td>
 <td><textarea name="comments" style="width: 50%; height: 100px"><?php echo $details->comments;?></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input type="hidden" name="detid" value="<?php echo $details->detid;?>" />
	 <input type="hidden" name="detregistration" value="<?php echo $details->registration;?>" />
	 <input type="hidden" name="fullname" value="<?php echo $details->fullname;?>" />
<input type="submit" name="submit" value="Edit Details" />
</td>
</tr>
</table>
</form>
<?php print_r($details);?>

Thankyou all for your help

Karl

  • Like 1
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...