Crew-Portal Posted July 30, 2007 Share Posted July 30, 2007 I am making a virtual airline manager and I cant seem to figure out why my data isnt going into the database: Here is the code for ?page=postflight <?php //Do not allow the page to be called directly. if(basename($_SERVER['PHP_SELF']) == "postflight.php") { header("Location: error403.php"); exit; } /******************************************************************************* This section creates the image verification. If you remove it, remove everything down through the end comment and close the php above with a ?> tag. Then, at the very bottom of the page, you also need to remove the php code. ********************************************************************************/ if (empty($_POST)) { ?> <form method="POST"> <table align="center" cellpadding="4" cellspacing="0" width="100%"> <tr> <td> <p>Please enter the code in the box below. The case doesn't matter.</p> </td> </tr> <tr> <td align="center"> <p><img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"></p> </td> </tr> <tr> <td align="center"> <p><input type="text" name="code" class="text"></p> </td> </tr> <tr> <td align="center"> <p><input type="submit" value="Verify code" class="button"></p> </td> </tr> <tr> <td align="center"> <p> <a href="?page=register">I can't read the code.</a></p> </td> </tr> </table> </form> <?php } else { //form is posted include("securimage.php"); $img = new Securimage(); $valid = $img->check($_POST['code']); if($valid == true) { /************************* End of image verification **************************/ ?> <center> <p> <form id="form1" name="form1" method="post" action="?page=postflightgo"> Log flight for user <?php echo $valid_user ?>, on <?php echo date('l dS \of F Y h:i:s A'); ?>.<br /> <table width="370" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="117" align="left" valign="top">Aircraft</td> <td width="253" align="left" valign="top"><select name="plane" class="login2" id="plane"> <option value="737-400" selected="selected">737-400</option> <option value="747-400">747-400</option> <option value="777-200LR">777-200LR</option> <option value="CRJ-200">CRJ-200</option> <option value="CRJ-700">CRJ-700</option> <option value="Bell 430">Bell 430</option> </select> </td> </tr> <tr> <td width="117" align="left" valign="top">Departure Airport </td> <td align="left" valign="top"><input name="depart" type="text" class="login2" id="depart" size="4" /> </td> </tr> <tr> <td width="117" align="left" valign="top">Arrival Airport </td> <td align="left" valign="top"><input name="arrival" type="text" class="login2" id="arrival" size="4" /></td> </tr> <tr> <td width="117" align="left" valign="top">Distance</td> <td align="left" valign="top"><input name="distance" type="text" class="login2" id="distance" value="" size="4" maxlength="4" length="40" /> Nautical Miles </td> </tr> <tr> <td width="117" align="left" valign="top">Passengers</td> <td align="left" valign="top"><input name="passengers" type="text" class="login2" id="distance" value="" size="4" maxlength="4" length="40" /></td> </tr> <tr> <td width="117" align="left" valign="top">Cargo</td> <td align="left" valign="top"><input name="cargo" type="text" class="login2" id="distance" value="" size="4" maxlength="4" length="40" /> KGs</td> </tr> <tr> <td width="117" align="left" valign="top">Total Time </td> <td align="left" valign="top"><select name="hour" class="login2" id="hour"> <option value="x" selected="selected">Hour</option> <option value="00">0</option> <option value="01">1</option> <option value="02">2</option> <option value="03">3</option> <option value="04">4</option> <option value="05">5</option> <option value="06">6</option> <option value="07">7</option> <option value="08">8</option> <option value="09">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> </select> <select name="minute" class="login2" id="select"> <option value="x" selected="selected">Minute</option> <option value="00">0</option> <option value="01">1</option> <option value="02">2</option> <option value="03">3</option> <option value="04">4</option> <option value="05">5</option> <option value="06">6</option> <option value="07">7</option> <option value="08">8</option> <option value="09">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> <option value="32">32</option> <option value="33">33</option> <option value="34">34</option> <option value="35">35</option> <option value="36">36</option> <option value="37">37</option> <option value="38">38</option> <option value="39">39</option> <option value="40">40</option> <option value="41">41</option> <option value="42">42</option> <option value="43">43</option> <option value="44">44</option> <option value="45">45</option> <option value="46">46</option> <option value="47">47</option> <option value="48">48</option> <option value="49">49</option> <option value="50">50</option> <option value="51">51</option> <option value="52">52</option> <option value="53">53</option> <option value="54">54</option> <option value="55">55</option> <option value="56">56</option> <option value="57">57</option> <option value="58">58</option> <option value="59">59</option> <option value="60">60</option> </select> <input name="second" type="hidden" id="second" value="00"></td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"><input name="submit" type="submit" class="login2" id="submit" value="Submit"> <input name="reset" type="reset" class="login2" value="Reset"></td> </tr> </table> </form> <?php /********************************************* If you remove the image verification, remove the php tag above & everything below. **********************************************/ } else { ?> <table align="center" cellpadding="4" cellspacing="0" width="80%"> <tr> <td> <p>Sorry, the code you entered was invalid. <a href="javascript:history.go(-1)">Go back</a> to try again.</p> </td> </tr> </table> <?php } } ?> And here is my code for the ?page=postflightdo <?php $flightnumberrand = rand(000, 999); $flt = 'AIV'; $fltnbr = $flt . $flightnumberrand; $fltdate = date("m-d-Y"); if(basename($_SERVER['PHP_SELF']) == "postflightgo.php") { header("Location: error403.php"); exit; } if ($_POST['depart'] == NULL){ echo 'Go Back And Put A Departure!'; exit; } else { if ($_POST['arrival'] == NULL){ echo 'Go Back And Put An Arrival!'; exit; } if ($_POST['distance'] == NULL){ echo 'Go Back And Put A Distance!'; exit; } $sql="INSERT INTO flights (CompanyName, PilotName, FlightID, FlightDate, AircraftName, NbrPassengers, CargoWeight, DepartureIcaoName, ArrivalIcaoName, TotalDistance, TotalBlockTime) VALUES ('None', '$valid_user', '$fltnbr', '$fltdate', $_POST[plane], $_POST[passengers], $_POST[cargo], $_POST[depart], $_POST[arrival], $_POST[distance], $_POST[hour] . $_POST[minute])"; $result = @mysql_query($sql,$connection) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error()); //Send the confirmation email. $to = $_POST['email']; $subject = $lang['memberconfirm']; $message = "$lang[hello]\n\n"; $message .= "$lang[loginis] $_POST[username]\n"; $message .= "$lang[pwis] $_POST[pass1]\n\n"; $message .= "$lang[followlink]\n"; $message .= "$siteurl/confirm.php?confirm=$rand_str\n\n"; $message .= "$lang[regards] $sitename\n"; $headers = "From: $sitemail\r\n"; $headers .= "Reply-To: $sitemail\r\n"; $headers .= "X-Mailer: PHP phpversion()"; mail($to, $subject, $message, $headers); //Display the successful registration message. ?> <table align="center" cellpadding="4" cellspacing="0" width="75%"> <tr> <td><p><?php echo $lang['linksent'] ?></p> <p><?php echo $lang['thanskjoin'] ?></p> </td> </tr> </table> <?php } ?> Everytime I try to post I get this error! Error: (1054) Unknown column Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 30, 2007 Share Posted July 30, 2007 Maybe uve written the wrong columns, but anyway the query cant work like that. Post variables must be called like $_POST['plane'] and in a query they must be like '{$_POST['plane']}' Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted July 30, 2007 Author Share Posted July 30, 2007 Nope Dont Work? > Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 30, 2007 Share Posted July 30, 2007 $sql="INSERT INTO flights (CompanyName, PilotName, FlightID, FlightDate, AircraftName, NbrPassengers, CargoWeight, DepartureIcaoName, ArrivalIcaoName, TotalDistance, TotalBlockTime) VALUES ('None', '$valid_user', '$fltnbr', '$fltdate', '{$_POST['plane']}', '{$_POST['passengers']}', '{'$_POST['cargo']}', '{$_POST['depart']}', '{$_POST['arrival']}', '{$_POST['distance']}', '{$_POST['hour']}' . '{$_POST['minute']}')"; also mysql_query should be mysql_query($sql) Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted July 30, 2007 Author Share Posted July 30, 2007 Im Trying this: $sql="INSERT INTO flights (CompanyName, PilotName, FlightID, FlightDate, AircraftName, NbrPassengers, CargoWeight, DepartureIcaoName, ArrivalIcaoName, TotalDistance, TotalBlockTime) VALUES ('"None"', '".$valid_user."', '".$fltnbr."', '".$fltdate."', '".$_POST["plane"]."', '".$_POST["passengers"]."', '".$_POST["cargo"]."', '".$_POST["depart"]."', '".$_POST["arr0ival"]."', '".$_POST["distance"]."', '".$_POST["hour"]."')"; And it still aint working?! Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted July 30, 2007 Author Share Posted July 30, 2007 SOLVED!!!!! $sql="INSERT INTO flights (CompanyName, PilotName, FlightID, FlightDate, AircraftName, NbrPassengers, CargoWeight, DepartureIcaoName, ArrivalIcaoName, TotalDistance, TotalBlockTime) VALUES ('None', '$valid_user', '$fltnbr', '$fltdate', '$_POST[plane]', '$_POST[passengers]', '$_POST[cargo]', '$_POST[depart]', '$_POST[arrival]', '$_POST[distance]', '$_POST[hour]:$_POST[minute]')"; Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 30, 2007 Share Posted July 30, 2007 your syntax is off. if you intend to break out of your delimiter (in this case, double quotes) you need to use the concatenation operator (the period) to append whatever's after it. you're doing this for variables, but not for the literal strings: $sql="INSERT INTO flights (CompanyName, PilotName, FlightID, FlightDate, AircraftName, NbrPassengers, CargoWeight, DepartureIcaoName, ArrivalIcaoName, TotalDistance, TotalBlockTime) VALUES ('None', '$valid_user', '$fltnbr', '$fltdate', '{$_POST['plane']}', '{$_POST['passengers']}', '{$_POST['cargo']}', '{$_POST['depart']}', '{$_POST['arr0ival']}', '{$_POST['distance']}', '{$_POST['hour']}')"; a few other notes: - when using double quotes, variables will automatically be interpolated - no need to concatenate them into the string - use single quotes when designating an array index (rather than double quotes, as you were using) - you can use braces {} to enclose an array item to have it interpolate, otherwise it will cause you string delimiter grief EDIT: posted just before me - glad to see it solved, but leaving this in namely for the array mention. Quote Link to comment 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.