Jump to content

[SOLVED] It just doesnt work, no errors it just wont work???


cpd

Recommended Posts

The line:

 

				mysql_query("INSERT INTO `flights` (flight_num,dep_airport,dep_icao,arr_airport,arr_icao,flight_time,dep_time,arr_time,day,route,aircraft_type,aircraft_reg) VALUES ('$FlightNum','$DepAirport','$DepICAO','$ArrAirport','$ArrICAO','$FlightTime','$DepTime','$ArrTime','$Day','$Route','$AircraftType','$AircraftReg')")or die(mysql_error());

 

Just simply wont work. I have defined all the variables above:

 

				$FlightNum = $_POST['flight_num']; $DepAirport = $_POST['dep_airport']; $DepICAO = $_POST['dep_icao']; $ArrAirport = $_POST['arr_airport']; $ArrICAO = $_POST['arr_icao']; $FlightTime = $_POST['flight_time']; $DepTime = $_POST['dep_time']; $ArrTime = $_POST['arr_time']; $Day = $_POST['day']; $Route = $_POST['route']; $AircraftType = $_POST['aircraft_type']; $AircraftRef = $_POST['aircraft_reg'];

 

And it still wont work. No errors are returned nothing. It just wont do it!

Try this and see what exactly you're trying to INSERT:

 

$sql = "INSERT INTO `flights` (flight_num,dep_airport,dep_icao,arr_airport,arr_icao,flight_time,dep_time,arr_time,day,route,aircraft_type,aircraft_reg) 
VALUES ('$FlightNum','$DepAirport','$DepICAO','$ArrAirport','$ArrICAO','$FlightTime','$DepTime','$ArrTime','$Day','$Route','$AircraftType','$AircraftReg')";

echo $sql;

mysql_query($sql) or die(mysql_error());?>

After doing what youve suggested ive come to the conclusion that its not working because it doesnt pass the error checking. It didnt print the $sql thats why ive come to this conclusion. Here is the script:

 

		if($_POST['submit']) {
		if(empty($_POST['flight_num']) || empty($_POST['dep_airport']) || empty($_POST['dep_icao']) || empty($_POST['arr_airport']) || empty($_POST['arr_icao']) || empty($_POST['flight_time']) || empty($_POST['dep_time']) || empty($_POST['arr_time']) || $_POST['day'] == "null" || empty($_POST['route']) || empty($_POST['aircraft_type']) || empty($_POST['aircraft_ref'])) {
			$ERROR = array();
			if(empty($_POST['flight_num'])) {
				$ERROR[] = "Please enter a flight number";
			}
			if(empty($_POST['dep_airport'])) {
				$ERROR[] = "Please enter the Departure Airport";
			}
			if(empty($_POST['dep_icao'])) {
				$ERROR[] = "Please enter the Departure ICAO";
			}
			if(empty($_POST['arr_airport'])) {
				$ERROR[] = "Please enter the Arrival Airport";
			}
			if(empty($_POST['arr_icao'])) {
				$ERROR[] = "Please enter the Arrival ICAO";
			}
			if(empty($_POST['flight_time'])) {
				$ERROR[] = "Please enter a Flight Time";
			}
			if(empty($_POST['dep_time'])) {
				$ERROR[] = "Please enter a Departure Time";
			}
			if(empty($_POST['arr_time'])) {
				$ERROR[] = "Please enter an Arrival Time";
			}
			if($_POST['day'] == "null") {
				$ERROR[] = "Please select a Day for the Flight";
			}
			if(empty($_POST['route'])) {
				$ERROR[] = "Please enter a route";
			}
			if(empty($_POST['aircraft_type'])) {
				$ERROR[] = "Please enter an aircraft type";
			}
			if(empty($_POST['aircraft_reg'])) {
				$ERROR[] = "Please enter an Aircraft Registration";
			}
			$FlightNum = $_POST['flight_num']; $DepAirport = $_POST['dep_airport']; $DepICAO = $_POST['dep_icao']; $ArrAirport = $_POST['arr_airport']; $ArrICAO = $_POST['arr_icao']; $FlightTime = $_POST['flight_time']; $DepTime = $_POST['dep_time']; $ArrTime = $_POST['arr_time']; $Route = $_POST['route']; $AircraftType = $_POST['aircraft_type']; $AircraftReg = $_POST['aircraft_reg'];
		} else {
			$FlightNum = $_POST['flight_num']; $DepAirport = $_POST['dep_airport']; $DepICAO = $_POST['dep_icao']; $ArrAirport = $_POST['arr_airport']; $ArrICAO = $_POST['arr_icao']; $FlightTime = $_POST['flight_time']; $DepTime = $_POST['dep_time']; $ArrTime = $_POST['arr_time']; $Day = $_POST['day']; $Route = $_POST['route']; $AircraftType = $_POST['aircraft_type']; $AircraftRef = $_POST['aircraft_reg'];
			$sql = "INSERT INTO `flights` (flight_num,dep_airport,dep_icao,arr_airport,arr_icao,flight_time,dep_time,arr_time,day,route,aircraft_type,aircraft_reg) VALUES ('$FlightNum','$DepAirport','$DepICAO','$ArrAirport','$ArrICAO','$FlightTime','$DepTime','$ArrTime','$Day','$Route','$AircraftType','$AircraftReg')";
			echo $sql;
			//mysql_query("INSERT INTO `flights` (flight_num,dep_airport,dep_icao,arr_airport,arr_icao,flight_time,dep_time,arr_time,day,route,aircraft_type,aircraft_reg) VALUES ('$FlightNum','$DepAirport','$DepICAO','$ArrAirport','$ArrICAO','$FlightTime','$DepTime','$ArrTime','$Day','$Route','$AircraftType','$AircraftReg')")or die(mysql_error());

I hate posting long bits of code like this but i think its the only way for you guys to see the whole page.

 

	mysql_connect('localhost','root','christopher');
mysql_select_db('euro');
if($_GET['content'] == "show_flights") {
	include('show_flights.php');
} else {
	if($_POST['submit']) {
		if(empty($_POST['flight_num']) || empty($_POST['dep_airport']) || empty($_POST['dep_icao']) || empty($_POST['arr_airport']) || empty($_POST['arr_icao']) || empty($_POST['flight_time']) || empty($_POST['dep_time']) || empty($_POST['arr_time']) || $_POST['day'] == "null" || empty($_POST['route']) || empty($_POST['aircraft_type']) || empty($_POST['aircraft_ref'])) {
			$ERROR = array();
			if(empty($_POST['flight_num'])) {
				$ERROR[] = "Please enter a flight number";
			}
			if(empty($_POST['dep_airport'])) {
				$ERROR[] = "Please enter the Departure Airport";
			}
			if(empty($_POST['dep_icao'])) {
				$ERROR[] = "Please enter the Departure ICAO";
			}
			if(empty($_POST['arr_airport'])) {
				$ERROR[] = "Please enter the Arrival Airport";
			}
			if(empty($_POST['arr_icao'])) {
				$ERROR[] = "Please enter the Arrival ICAO";
			}
			if(empty($_POST['flight_time'])) {
				$ERROR[] = "Please enter a Flight Time";
			}
			if(empty($_POST['dep_time'])) {
				$ERROR[] = "Please enter a Departure Time";
			}
			if(empty($_POST['arr_time'])) {
				$ERROR[] = "Please enter an Arrival Time";
			}
			if($_POST['day'] == "null") {
				$ERROR[] = "Please select a Day for the Flight";
			}
			if(empty($_POST['route'])) {
				$ERROR[] = "Please enter a route";
			}
			if(empty($_POST['aircraft_type'])) {
				$ERROR[] = "Please enter an aircraft type";
			}
			if(empty($_POST['aircraft_reg'])) {
				$ERROR[] = "Please enter an Aircraft Registration";
			}
			$FlightNum = $_POST['flight_num']; $DepAirport = $_POST['dep_airport']; $DepICAO = $_POST['dep_icao']; $ArrAirport = $_POST['arr_airport']; $ArrICAO = $_POST['arr_icao']; $FlightTime = $_POST['flight_time']; $DepTime = $_POST['dep_time']; $ArrTime = $_POST['arr_time']; $Route = $_POST['route']; $AircraftType = $_POST['aircraft_type']; $AircraftReg = $_POST['aircraft_reg'];
		} else {
			$FlightNum = $_POST['flight_num']; $DepAirport = $_POST['dep_airport']; $DepICAO = $_POST['dep_icao']; $ArrAirport = $_POST['arr_airport']; $ArrICAO = $_POST['arr_icao']; $FlightTime = $_POST['flight_time']; $DepTime = $_POST['dep_time']; $ArrTime = $_POST['arr_time']; $Day = $_POST['day']; $Route = $_POST['route']; $AircraftType = $_POST['aircraft_type']; $AircraftRef = $_POST['aircraft_reg'];
			$sql = "INSERT INTO `flights` (flight_num,dep_airport,dep_icao,arr_airport,arr_icao,flight_time,dep_time,arr_time,day,route,aircraft_type,aircraft_reg) VALUES ('$FlightNum','$DepAirport','$DepICAO','$ArrAirport','$ArrICAO','$FlightTime','$DepTime','$ArrTime','$Day','$Route','$AircraftType','$AircraftReg')";
			echo $sql;
			//mysql_query("INSERT INTO `flights` (flight_num,dep_airport,dep_icao,arr_airport,arr_icao,flight_time,dep_time,arr_time,day,route,aircraft_type,aircraft_reg) VALUES ('$FlightNum','$DepAirport','$DepICAO','$ArrAirport','$ArrICAO','$FlightTime','$DepTime','$ArrTime','$Day','$Route','$AircraftType','$AircraftReg')")or die(mysql_error());
		}
	}
?>
<html>
<head>
<title>Insert Flight</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<? if($ERROR) {print "<div class=\"error\"><u>An error has occured</u><br /><ol>"; foreach($ERROR as $E) {print "<li>".$E."</li>";} print "</ol></div>";} ?>
<form method="post">
	<table cellspacing="0" cellpadding="0" class="tbl1">
		<tr><td>Flight Num:</td><td align="right"><input value="<? print $FlightNum; ?>" type="text" name="flight_num" /></td></tr>
		<tr><td>Dep Airport:</td><td align="right"><input value="<? print $DepAirport; ?>" type="text" name="dep_airport" /></td></tr>
		<tr><td>Dep ICAO:</td><td align="right"><input value="<? print $DepICAO; ?>" type="text" name="dep_icao" maxlength="4" /></td></tr>
		<tr><td>Arr Airport:</td><td align="right"><input value="<? print $ArrAirport; ?>" type="text" name="arr_airport" /></td></tr>
		<tr><td>Arr ICAO:</td><td align="right"><input value="<? print $ArrICAO; ?>" type="text" name="arr_icao" maxlength="4" /></td></tr>
		<tr><td>Flight Time:</td><td align="right"><input value="<? print $FlightTime; ?>" type="text" name="flight_time" /></td></tr>
		<tr><td>Dep Time:</td><td align="right"><input value="<? print $DepTime; ?>" type="text" name="dep_time" /></td></tr>
		<tr><td>Arr Time:</td><td align="right"><input value="<? print $ArrTime; ?>" type="text" name="arr_time" /></td></tr>
		<tr><td>Day:</td><td align="right"><select name="day"><option value="null">---------------</option><option value="Monday">Monday</option><option value="Tuesday">Tuesday</option><option value="Wednesday">Wednesday</option><option value="Thursday">Thursday</option><option value="Friday">Friday</option><option value="Saturday">Saturday</option><option value="Sunday">Sunday</option></select></td></tr>
	</table>
		<div class="textarea">Route:<br /><textarea name="route"><? print $Route; ?></textarea></div>
	<table cellspacing="0" cellpadding="0" class="tbl2">
		<tr><td>Aircraft Type:</td><td align="right"><input value="<? print $AircraftType; ?>" type="text" name="aircraft_type" /></td></tr>
		<tr><td>Aircraft Registration:</td><td align="right"><input value="<? print $AircraftReg; ?>" type="text" name="aircraft_reg" /></td></tr>
		<tr><td></td><td><input type="submit" name="submit" value="Submit" /></td></tr>
	</table>
</form>
<div class="link"><a href="flights.php?content=show_flights">Show all Flights</a></div>
</body>
</html>
<? } ?>

You should use: (I think I have key and value switched...)

 

if(isset($_POST['submit'])) {

 

You should also just use a foreach loop for your posts instead of hardcoding each one in.  For example:

 

$errors = FALSE;
foreach($_POST as $value => $key)
{
  if(empty($value))
  {
     $ERROR[] = "Please enter for:" . $key;
     $errors = TRUE;
  }
}
//$rest of your code

The source doesnt actually show anything with regards to the PHP apart from the values of each input where ive set it to print what i entered when i submited it.

 

If i use the error_reporting i get:

 

 

Notice: Undefined index: content in C:\xampp\htdocs\euro\MAKING_FLIGHTS\flights.php on line 6

Guys i thought about it logically. And realised that it can only be going into the Error part if it initially thought there was an error so i double checked all the || "Or" tags and realised i spelt "ref" rather then "reg" =)

 

Thanks for the help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.