Jump to content

[SOLVED] Yet another PHP probelm


themightydude

Recommended Posts

Ok...here is the problem now.

 

This is the way the pages are layed out..

 

show_records.php --> edit.php --> update.php

 

Show records just displays all the records and puts them into an array so I can have an edit link, and delete button for each record.

 

When I hit edit, it takes me to the edit.php which pulls the id from the previous page then does a mysql query against that ID to populate the text boxes with the current data.

 

This is the edit.php code..I've cleaned it up some to make it easier to read.

 

<html>
<body>

<?php
$dbhost = 'localhost';
$dbuser = 'xxxx';
$dbpass = 'xxxx';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
		('Error Connectiong to MySQL');
mysql_select_db('uam') or die(mysql_error());


if (empty($_GET['id'])) {

$search = FALSE;
$message .= '<p>Error Editing File</p>';
} else {


// SQL QUERY

$query = "SELECT * from value where id = '$_GET[id]'" or die(mysql_error());
print "QUERY: $query";
$result = mysql_query($query);


while($row = mysql_fetch_array($result))



{

$year = 		     	$row['year'];
$aircraft_fleet = 		$row['aircraft_fleet'];
$tail_number = 			$row['tail_number'];
$engines = 				$row['engines'];
$apu = 					$row['apu'];
$lease_value =			$row['lease_value'];
$engine_value = 		$row['engine_value'];
$engine_lease_value =   $row['engine_lease_value'];
$aircraft_value =	 	$row['aircraft_value'];
$serial_number =	 	$row['serial_number'];
$vintage = 			 	$row['vintage'];
$apu_lease_value = 	 	$row['apu_lease_value'];
$data_type =         	$row['data_type'];
$notes =             	$row['notes'];
$engine_mfg =        	$row['engine_mfg'];
$month =             	$row['month'];
$id = 					$row['id'];


}

}




?>
HTML ID <?php print $id; ?>

<form method="post" action="update.php">
<strong>CURRENT VALUES:</strong><br />
<br />
<br />
Year:<input name="year" type="text" value="<?php print $year; ?>" />

Notes:</p>
<div style="position: absolute; width: 100px; height: 165px; z-index: 1; left: 470px; top: 210px" id="layer1">

	<textarea name="notes"  style="width: 285px; height: 170px" rows="1" cols="20"><?php print $notes; ?></textarea>
</div>



<p>Aircraft Type: 		<input name="aircraft_fleet" type="text" value="<?php print $aircraft_fleet; ?>"></p>
<p>Tail Number: 		<input name="tail_number" type="text" value="<?php print $tail_number; ?>"></p> 
<p>Engine:				<input name="engines" type="text" value="<?php print $engines; ?>"></p>
<p>APU: 				<input name="apu" type="text" value="<?php print $apu; ?>"></p>
<p>Lease Value:			<input name="lease_value" type="text" value="<?php print $lease_value; ?>"></p>
<p>Engine Value: 		<input name="engine_value" type="text" value="<?php print $engine_value; ?>"></p>
<p>Engine Lease Value:	<input name="engine_lease_value" type="text" value="<?php print $engine_lease_value; ?>"></p>
<p>Aircraft Value:		<input name="aicraft_value" type="text" value="<?php print $aircraft_value; ?>"></p>
<p>Serial Number:		<input name="serial_number" type="text" value="<?php print $serial_number; ?>"></p>
<p>Vintage:				<input name="vintage" type="text" value="<?php print $vintage; ?>"></p>
<p>APU Lease Value:		<input name="apu_lease_value" type="text" value="<?php print $apu_lease_value; ?>"></p>
<p style="height: 20px"><br />
Data Type:
<input name="data_type" type="text" value="<?php print $data_type; ?>"></p>
<p> </p>
<p style="height: 20px">Engine Manufacturer:<input name="engine_mfg" type="text" value="<?php print $engine_mfg; ?>"></p>

<p style="height: 20px">Month:;<input name="month" type="text" value="<?php print $month; ?>" style="width: 152px"></p>

<input name="id" type="hidden" value="<?php print $id; ?>">

<input type="submit" value="UPDATE">


<?php




mysql_free_result($result);

mysql_close();







?>


</form>
</body>
</html>

 

That code works fine...it populates every field and there is no problem. Once the user hits submit it calls update.php which does the actual update into MySQL...this is where the problem begins. All fields are being populated except for 1 field that does not pull any values from edit.php, and I can't figure it out. the ac value field is populated in edit.php, but not in update.php.

 

As you can see in the below code, I've done a few tests.

 

In my query, I was originally using $_POST for the query...then I changed that and defined variables for the mysql data and re-did the query with those.

 

As you can see, I'm doing 2 things here...first I'm printing the values of the data before it gets to the mysql query, then I'm printing the mysql query.

 

The field that isn't pulling data is the ac value field...$aircraft_value....

 

This is the update.php code

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<?php
$dbhost = 'localhost';
$dbuser = 'xxxx';
$dbpass = 'xxxx';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
		('Error Connectiong to MySQL');
mysql_select_db('uam') or die(mysql_error());

$year = 						$_POST['year'];
$aircraft_fleet =				$_POST['aircraft_fleet'];
$tail_number = 					$_POST['tail_number'];
$engines = 						$_POST['engines'];
$apu =							$_POST['apu'];
$lease_value = 					$_POST['lease_value'];
$engine_value = 				$_POST['engine_value'];
$engine_lease_value = 			$_POST['engine_lease_value'];
$aircraft_value = 				$_POST['aircraft_value'];
$serial_number = 				$_POST['serial_number'];
$vintage = 						$_POST['vintage'];
$apu_lease_value = 				$_POST['apu_lease_value'];
$data_type = 					$_POST['data_type'];
$notes = 						$_POST['notes'];
$engine_mfg = 					$_POST['engine_mfg'];
$month = 						$_POST['month'];
$id = 							$_POST['id'];


print "year $year <br />";
print "actype $aircraft_fleet <br />";
print "tail $tail_number <br />";
print "engines$engines <br />";
print "apu$apu <br />";
print "lease value$lease_value <br />";
print "engine value$engine_value <br />";
print "engine lease value $engine_lease_value <br />";
print "ac value$aircraft_value <br />";
print "sn$serial_number <br />";
print "vintage$vintage <br />";
print "apu lease value$apu_lease_value <br />";
print "data type$data_type<br />";
print "notes$notes <br />";
print "engine_mfg$engine_mfg <br />";
print "month$month <br />";
print "id$id <br />";


// SQL QUERY

$query = "UPDATE value SET year='$year', aircraft_fleet='$aircraft_fleet', tail_number='$tail_number', engines='$engines',apu='$apu', lease_value='$lease_value', engine_value='$engine_value', engine_lease_value='$engine_lease_value', aircraft_value='$aircraft_value', serial_number='$serial_number', vintage='$vintage', apu_lease_value='$apu_lease_value', data_type='$data_type', notes='$notes', engine_mfg='$engine_mfg', month='$month' where id='$id'";
print $query;
/*if (!mysql_query($query,$conn))
{
	die('Error: ' . mysql_error());
}
else {
	echo '<p><b>1 Record Added</p></p>';
	echo '<p><b><a href="default.php">Go Back</a></p>';

}

*/

mysql_close(); // close database connection





?>
<body>
</body>

</html>

 

When I print the mysql query it looks like this

UPDATE value SET year='AAbb', aircraft_fleet='AAbb', tail_number='AAbb', engines='AE3007bb',apu='AAbb', lease_value='AAbb', engine_value='AAbb', engine_lease_value='AAbb', aircraft_value='', serial_number='AAbb', vintage='AAbb', apu_lease_value='AAbb', data_type='AAbb', notes='AAAAAAbbb', engine_mfg='Pratt & Whitneybb', month='Aprilbb' where id='265'

 

As  you can see, aircraft_value has a " instead of the data...no idea :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.