AyKay47 Posted August 5, 2011 Share Posted August 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252823 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252825 Share on other sites More sharing options...
AyKay47 Posted August 5, 2011 Share Posted August 5, 2011 okay, if you want to hold his hand, by all means, I don't have a problem with that...It's better to understand the code than to simply be given it....i agree Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252826 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252827 Share on other sites More sharing options...
dudejma Posted August 5, 2011 Author Share Posted August 5, 2011 Haha, yeah. I probably would. I put that code and the page goes blank. Nothing comes up. Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252836 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 remove this line, come on OP, you gotta do some thinking here. die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252838 Share on other sites More sharing options...
AyKay47 Posted August 5, 2011 Share Posted August 5, 2011 remove this line, come on OP, you gotta do some thinking here. die(mysql_error()); My point exactly... Ha.. I just don't have time to do a walkthrough, although I encourage it. Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252848 Share on other sites More sharing options...
dudejma Posted August 5, 2011 Author Share Posted August 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252892 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 haha, looks like my prediction came true. run this die(mysql_error()); right after the query Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252894 Share on other sites More sharing options...
dudejma Posted August 5, 2011 Author Share Posted August 5, 2011 Still get the same error. What does the error mean? Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252914 Share on other sites More sharing options...
phpSensei Posted August 5, 2011 Share Posted August 5, 2011 whats the output of the error? Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252922 Share on other sites More sharing options...
dudejma Posted August 6, 2011 Author Share Posted August 6, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252927 Share on other sites More sharing options...
AyKay47 Posted August 6, 2011 Share Posted August 6, 2011 Are you checking to make sure $_GET['id] is set before executing your dependent code? Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252928 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252929 Share on other sites More sharing options...
dudejma Posted August 6, 2011 Author Share Posted August 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252942 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 show me URL when your viewing this code. Its also case sensitive... it has to be id not ID Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252947 Share on other sites More sharing options...
dudejma Posted August 6, 2011 Author Share Posted August 6, 2011 I attached an image of the upper left hand corner. It's a locked page (the session part). That's what I get when I hit submit. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252953 Share on other sites More sharing options...
AyKay47 Posted August 6, 2011 Share Posted August 6, 2011 We will need to see the code where you are passing the id through the URL. Please paste the code onto this thread. I'm mobile... Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252963 Share on other sites More sharing options...
dudejma Posted August 6, 2011 Author Share Posted August 6, 2011 <a href="editPirep.php?id=' . $row['id'] . '">Edit</a> Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1252972 Share on other sites More sharing options...
phpSensei Posted August 6, 2011 Share Posted August 6, 2011 PM me the admin password, you can change it later, I want to get to the bottom of this. I can't access editPirep.php Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1253023 Share on other sites More sharing options...
dudejma Posted August 6, 2011 Author Share Posted August 6, 2011 I found a way to fix it! In the form, I just added a hidden field and gave it the value of the id. It works that way, thanks for all the help guys! Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1253507 Share on other sites More sharing options...
jkkenzie Posted December 4, 2011 Share Posted December 4, 2011 Did you solve this problem? I think i have the answer. Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1294254 Share on other sites More sharing options...
Pikachu2000 Posted December 4, 2011 Share Posted December 4, 2011 Did you solve this problem? I think i have the answer. I found a way to fix it! My crystal ball says 'yes'. Quote Link to comment https://forums.phpfreaks.com/topic/243959-header/page/2/#findComment-1294307 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.