Jump to content

Header


dudejma

Recommended Posts

Alright, lets see what the cause of the mysql error is.

 

try this and let me know the ouput.

 

<?php
session_start();

ini_set ("display_errors", "1");
error_reporting(E_ALL ^ E_NOTICE);
require 'include/sql.php';

$errors = "";

$adminid = $_SESSION['adminid'];
$adminpass = $_SESSION['adminpass'];
$position = $_SESSION['position'];

if(!isset($adminid) || !isset($adminpass) || !isset($position)) {
header("Location: index.php");
}



$id = $_GET['id'];

$sql = "SELECT * FROM pireps WHERE `id` = $id";
$result = mysql_query($sql);
die(mysql_error());
$row = mysql_fetch_array($result);

$pilotid = $row['pilotID'];
$flightNum = $row['flight'];
$departure = $row['dept'];
$arrivalAirport = $row['arrival'];
$hours = $row['flightTime'];
$fuelUsed = $row['fuel'];
$aircraftUsed = $row['aircraft'];
$statusPirep = $row['status'];
$pilotComment = $row['comment'];

print "THE VALUE OF PILOT ID IS: ". $pilotid;

if (isset($_POST['submit'])) {
$flight = mysql_escape_string($_POST['flight']);
$dept = mysql_escape_string(strtoupper($_POST['dept']));
$arrival = mysql_escape_string(strtoupper($_POST['arrival']));
$flightTime = mysql_escape_string($_POST['flightTime']);
$fuel = mysql_escape_string($_POST['fuel']);
$aircraft = $_POST['aircraft'];
$status = $_POST['status'];
$comments = $_POST['comments'];

$sql2 = "UPDATE pireps SET flight='$flight', dept='$dept', arrival='$arrival', flightTime='$flightTime', fuel='$fuel', aircraft='$aircraft', status='$status', comments='$comment' WHERE `id` = '$id' ";

$result2 = mysql_query($sql2) or die("An error has occured. Please contact the webmaster with the following error: " . mysql_error());
print "THE VALUE OF PILOT ID IS: ". $pilotid;

#header("Location: logbook.php?pid=" . $pilotid);

} else {

print "Form was not submitted";

}

?>

<!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=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
	limitField.value = limitField.value.substring(0, limitNum);
} else {
	limitCount.value = limitNum - limitField.value.length;
}
}
</script>
<title>VAAdministration Center</title>
</head>

<body>
<!-- Begins Wrapper -->
<div id="wrapper">
	<!-- Begins Header -->
	<div id="header">
	<center>
	<img src="images/aadmin.jpg" />
	</center>
	</div>
	<!-- Ends header -->
			<!-- Begins Faux -->
			<div id="faux">
				<!-- Begins left column -->
				<div id="leftcolumn">
				<br />
				<?php include 'include/menu.php'; ?>
				</div>
				<!-- Ends left column -->
					<!-- Begins content -->
					<div id="content">
					<center>
					<!-- Begins page title -->
					<br />
					<font color="red" size="6"><b>Edit </font><font color="blue" size="6">PIREP</b></font>
					<br />
					<br />
					<br />
					<?php echo $errors; ?>
					<table border="0" cellpadding="4" cellspacing="4">
					<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
					<tr>
  <td><b>Flight Number: </b></td>
  <td><input type="text" size="8" value="<?php echo $flightNum; ?>" name="flight" maxlength="7"/></td>
  </tr>
  <tr>
  <td><b>Departure Airport (ICAO): </b></td>
  <td><input type="text" size="4" value="<?php echo $departure; ?>" name="dept" maxlength="4"/></td>
  </tr>
  <tr>
  <td><b>Arrival Airport (ICAO): </b></td>
  <td><input type="text" size="4" value="<?php echo $arrivalAirport; ?>" name="arrival" maxlength="4"/></td>
  </tr>
  <tr>
  <td><b>Flight Time</b></td>
  <td><input type="text" size="1" value="<?php echo $hours; ?>" name="flightTime" maxlength="4" /></td>
  </tr>
  <tr>
  <td><b>Fuel (lbs.): </b></td>
  <td><input type="text" size="10" value="<?php echo $fuelUsed; ?>" name="fuel" maxlength="6"/></td>
  </tr>
  <tr>
  <td><b>Aircraft: </b></td>
  <td><select name="aircraft">
  <option value="ATR-72" <?php if ($aircraftUsed == 'ATR-72') echo 'selected="selected"'; ?>>ATR-72</option>
  <option value="ERJ-135" <?php if ($aircraftUsed == 'ERJ-135') echo 'selected="selected"'; ?>>ERJ-135</option>
  <option value="ERJ-140" <?php if ($aircraftUsed == 'ERJ-140') echo 'selected="selected"'; ?>>ERJ-140</option>
  <option value="ERJ-145" <?php if ($aircraftUsed == 'ERJ-145') echo 'selected="selected"'; ?>>ERJ-145</option>
  <option value="CRJ-700" <?php if ($aircraftUsed == 'CRJ-700') echo 'selected="selected"'; ?>>CRJ-700</option>
  <option value="MD-80" <?php if ($aircraftUsed == 'MD-80') echo 'selected="selected"'; ?>>McDonnel Douglas MD-80</option>
  <option value="B737" <?php if ($aircraftUsed == 'B737') echo 'selected="selected"'; ?>>Boeing 737-800</option>
  <option value="B757" <?php if ($aircraftUsed == 'B757') echo 'selected="selected"'; ?>>Boeing 757</option>
  <option value="B767" <?php if ($aircraftUsed == 'B767') echo 'selected="selected"'; ?>>Boeing 767</option>
  <option value="B777" <?php if ($aircraftUsed == 'B777') echo 'selected="selected"'; ?>>Boeing 777</option>
  </select></td>
  </tr>
  <tr>
  <td><b>Status: </b></td>
  <td><select name="status">
  <option value="1" <?php if ($statusPirep == '1') echo 'selected="selected"'; ?>>Approved</option>
  <option value="2" <?php if ($statusPirep == '2') echo 'selected="selected"'; ?>>Declined</option></select></td>
  </tr>
  <tr>
  <td><b>Comments: </b>
  <td><textarea cols="20" rows="15" name="comments" onKeyDown="limitText(this.form.comments,this.form.countdown,350);"  onKeyUp="limitText(this.form.comments,this.form.countdown,350);"><?php echo $pilotComment; ?></textarea><br>
          You have <input readonly type="text" name="countdown" size="3" value="350"> characters left.</font></td>
  </td>
  </tr>
  <tr>
  <td></td>
  <td><input type="submit" value="Submit" name="submit" class="myButton"/></td>
  </tr>
  </table>
  </form>

					</center>
					<!-- DO NOT TOUCH -->
					<br />
					<!-- DONE -->
					</div>
				<!-- Begins right column -->
				<div id="rightcolumn">
				<br />
				</div>
				<!-- Ends right column -->
	<!-- Begins footer -->
	<div id="footer">
	<center>
	<?php include 'include/footer.php'; ?>
	</center>
	</div>
	<!-- Ends footer -->
			</div>
</div>
</body>
</html>

the error is being triggered because the $_GET['id'] value is empty...thus the query returns false....and actually all of the other errors that the OP are caused by the empty value as well

Link to comment
Share on other sites

AyKay47, I just want to slowly show him his problems in his code, this way he can debug it himself in the future.. I want him to see every aspect of debugging and where he may be going wrong.

 

Notice: Undefined index: id in /home/virtuala/public_html/site/admin/editPirep.php on line 20

 

This hints it pretty much, however I remember a time when I started programming and people did the debugging for me without telling me how they came about finding the problem.

Link to comment
Share on other sites

Your completely right, the problem is solved and there's no need to keep going..

 

however I want him to know how to fix this problem in the future with a simple die(mysql_erorr()); which would lead to the GET.

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtuala/public_html/site/admin/editPirep.php on line 24

 

 

Trust me, he will make another thread if we don't explain it.

Link to comment
Share on other sites

This is the error I get:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtuala/public_html/site/admin/editPirep.php on line 24

 

From this, I'm guessing it means that $row = mysql_fetch_array isn't working..? I'm not the best at PHP if you can't tell. XD

Link to comment
Share on other sites

I updated and cleaned your code, and fixed some errors, let us know what the output is

 

 

<?php
session_start();
ini_set ("display_errors", "1");
error_reporting(E_ALL ^ E_NOTICE);
require 'include/sql.php';
$errors = "";
$adminid = $_SESSION['adminid'];
$adminpass = $_SESSION['adminpass'];
$position = $_SESSION['position'];

if((!isset($adminid)) || (!isset($adminpass)) || (!isset($position))) { header("Location: index.php"); exit();}

if((isset($_GET['id'])&&($_GET['id'] !="")){

        $id = mysql_real_escape_string($_GET['id']);
$result = mysql_query( "SELECT * FROM `pireps` WHERE `id` = '$id' ") or die(mysql_error());
$row = mysql_fetch_array($result);

$pilotid = $row['pilotID'];
$flightNum = $row['flight'];
$departure = $row['dept'];
$arrivalAirport = $row['arrival'];
$hours = $row['flightTime'];
$fuelUsed = $row['fuel'];
$aircraftUsed = $row['aircraft'];
$statusPirep = $row['status'];
$pilotComment = $row['comment'];

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

			$flight = mysql_escape_string($_POST['flight']);
			$dept = mysql_escape_string(strtoupper($_POST['dept']));
			$arrival = mysql_escape_string(strtoupper($_POST['arrival']));
			$flightTime = mysql_escape_string($_POST['flightTime']);
			$fuel = mysql_escape_string($_POST['fuel']);
			$aircraft = $_POST['aircraft'];
			$status = $_POST['status'];
			$comments = $_POST['comments'];

			$sql2 = "UPDATE pireps SET flight='$flight', dept='$dept', arrival='$arrival', flightTime='$flightTime', fuel='$fuel', aircraft='$aircraft', status='$status', comments='$comment' WHERE `id` = '$id' ";

			$result2 = mysql_query($sql2) or die("An error has occured. Please contact the webmaster with the following error: " . mysql_error());

			header("Location: logbook.php?pid=" . $pilotid);

	} else {

			print "Form was not submitted";

	}
}else{

print "Id is not set, and its empty";

}
?>

<!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=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
if (limitField.value.length > limitNum) {
	limitField.value = limitField.value.substring(0, limitNum);
} else {
	limitCount.value = limitNum - limitField.value.length;
}
}
</script>
<title>VAAdministration Center</title>
</head>

<body>
<!-- Begins Wrapper -->
<div id="wrapper">
	<!-- Begins Header -->
	<div id="header">
	<center>
	<img src="images/aadmin.jpg" />
	</center>
	</div>
	<!-- Ends header -->
			<!-- Begins Faux -->
			<div id="faux">
				<!-- Begins left column -->
				<div id="leftcolumn">
				<br />
				<?php include 'include/menu.php'; ?>
				</div>
				<!-- Ends left column -->
					<!-- Begins content -->
					<div id="content">
					<center>
					<!-- Begins page title -->
					<br />
					<font color="red" size="6"><b>Edit </font><font color="blue" size="6">PIREP</b></font>
					<br />
					<br />
					<br />
					<?php echo $errors; ?>
					<table border="0" cellpadding="4" cellspacing="4">
					<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
					<tr>
  <td><b>Flight Number: </b></td>
  <td><input type="text" size="8" value="<?php echo $flightNum; ?>" name="flight" maxlength="7"/></td>
  </tr>
  <tr>
  <td><b>Departure Airport (ICAO): </b></td>
  <td><input type="text" size="4" value="<?php echo $departure; ?>" name="dept" maxlength="4"/></td>
  </tr>
  <tr>
  <td><b>Arrival Airport (ICAO): </b></td>
  <td><input type="text" size="4" value="<?php echo $arrivalAirport; ?>" name="arrival" maxlength="4"/></td>
  </tr>
  <tr>
  <td><b>Flight Time</b></td>
  <td><input type="text" size="1" value="<?php echo $hours; ?>" name="flightTime" maxlength="4" /></td>
  </tr>
  <tr>
  <td><b>Fuel (lbs.): </b></td>
  <td><input type="text" size="10" value="<?php echo $fuelUsed; ?>" name="fuel" maxlength="6"/></td>
  </tr>
  <tr>
  <td><b>Aircraft: </b></td>
  <td><select name="aircraft">
  <option value="ATR-72" <?php if ($aircraftUsed == 'ATR-72') echo 'selected="selected"'; ?>>ATR-72</option>
  <option value="ERJ-135" <?php if ($aircraftUsed == 'ERJ-135') echo 'selected="selected"'; ?>>ERJ-135</option>
  <option value="ERJ-140" <?php if ($aircraftUsed == 'ERJ-140') echo 'selected="selected"'; ?>>ERJ-140</option>
  <option value="ERJ-145" <?php if ($aircraftUsed == 'ERJ-145') echo 'selected="selected"'; ?>>ERJ-145</option>
  <option value="CRJ-700" <?php if ($aircraftUsed == 'CRJ-700') echo 'selected="selected"'; ?>>CRJ-700</option>
  <option value="MD-80" <?php if ($aircraftUsed == 'MD-80') echo 'selected="selected"'; ?>>McDonnel Douglas MD-80</option>
  <option value="B737" <?php if ($aircraftUsed == 'B737') echo 'selected="selected"'; ?>>Boeing 737-800</option>
  <option value="B757" <?php if ($aircraftUsed == 'B757') echo 'selected="selected"'; ?>>Boeing 757</option>
  <option value="B767" <?php if ($aircraftUsed == 'B767') echo 'selected="selected"'; ?>>Boeing 767</option>
  <option value="B777" <?php if ($aircraftUsed == 'B777') echo 'selected="selected"'; ?>>Boeing 777</option>
  </select></td>
  </tr>
  <tr>
  <td><b>Status: </b></td>
  <td><select name="status">
  <option value="1" <?php if ($statusPirep == '1') echo 'selected="selected"'; ?>>Approved</option>
  <option value="2" <?php if ($statusPirep == '2') echo 'selected="selected"'; ?>>Declined</option></select></td>
  </tr>
  <tr>
  <td><b>Comments: </b>
  <td><textarea cols="20" rows="15" name="comments" onKeyDown="limitText(this.form.comments,this.form.countdown,350);"  onKeyUp="limitText(this.form.comments,this.form.countdown,350);"><?php echo $pilotComment; ?></textarea><br>
          You have <input readonly type="text" name="countdown" size="3" value="350"> characters left.</font></td>
  </td>
  </tr>
  <tr>
  <td></td>
  <td><input type="submit" value="Submit" name="submit" class="myButton"/></td>
  </tr>
  </table>
  </form>

					</center>
					<!-- DO NOT TOUCH -->
					<br />
					<!-- DONE -->
					</div>
				<!-- Begins right column -->
				<div id="rightcolumn">
				<br />
				</div>
				<!-- Ends right column -->
	<!-- Begins footer -->
	<div id="footer">
	<center>
	<?php include 'include/footer.php'; ?>
	</center>
	</div>
	<!-- Ends footer -->
			</div>
</div>
</body>
</html>

Link to comment
Share on other sites

I get ID is not set, and it's empty. But how do I set it? I sent it to it and gave it a name. Or in other words, the link is: editPirep.php?id=Whatever id is and at the top, I get the ID from the url, what else do you have to do to set it?

Link to comment
Share on other sites

  • 3 months later...
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.