Jump to content

[SOLVED] MySQL Query Error


maxudaskin

Recommended Posts

Ok...

First Page sends information to the second page...

I have tried addslashes()... unsucessfully.

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' CYYZ, EGKK, Toronto, London, 20:55, 10:30, Ottawa, 8:35, 7)' at line 1

 

First Page

<?php
						if(!$logged_in){
   echo "<h1>Error!</h1>\n";
   echo "You are not currently logged in. Go to <a href=\"login.php\">Login.</a>";
}
else{
if($_SESSION['type'] == 1){
?>
                              <table width="400" border="0" cellspacing="1" cellpadding="0">
                                <tr>
                                  <td align="center" valign="top"><form id="form1" name="form1" method="post" action="addflight.php">
                                    <p align="left">
                                    <input name="flightnumber" type="text" id="flightnumber" maxlength="10" />
                                  Flight Number<br />
                                  <input name="dep" type="text" id="dep" maxlength="4" />
                                    Departure (ICAO Ex. CYYZ or EGKK) <br />
                                    <input name="depcity" type="text" id="depcity" />
Departure City<br />
<input name="dest" type="text" id="dest" maxlength="4" />
                                    Destination (ICAO) <br />
                                    <input name="destcity" type="text" id="destcity" />
                                    Destination City <br>
                                    <input name="deptime" type="text" id="deptime" value="00:00" maxlength="5" />
                                    Departure Time<br>
                                    <input name="desttime" type="text" id="desttime" value="00:00" maxlength="5" /> 
                                    Arrival Time
                                    <br>
                                    <input name="stop" type="text" id="stop" />
                                    Stopovers (City, Ex. Ottawa)<br>
                                    <input name="duration" type="text" id="duration" value="HH:MM" maxlength="5" /> 
                                    Duration<br>
                                    <input name="freq" type="text" id="freq" value="7" maxlength="1" /> 
                                    <span class="style17 style24"><span class="style26 style22">Frequency (Number of Days a Week)</span></span><br>
                                    <br>
                                    </p>
                                    <div>
                                      <input name="add" type="submit" id="add" value="Add Flight">
                                      <input name="reset" type="submit" id="reset" value="Reset Form">
                                    </div>
                                    <p align="left">  </p>
                                  </form>                                  </td>
                                </tr>
                              </table>
						  <?php }} ?>

 

Second Page

<?php
						if(!$logged_in){
   echo "<h1>Error!</h1>\n";
   echo "You are not currently logged in. Go to <a href=\"login.php\">Login.</a>";
}
else{
if($_SESSION['type'] == 1){
$con = mysql_connect("mysqlsomeurl.net","dbadmin","admin");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db($database_LeadHost, $LeadHost);
  if($_SESSION['type'] == 1){
  $flightnumber      = $_POST['flightnumber'];
  $departure         = $_POST['dep'];
  $destination       = $_POST['dest'];
  $departurecity     = $_POST['depcity'];
  $destinationcity   = $_POST['destcity'];
  $departuretime     = $_POST['deptime'];
  $arrivaltime       = $_POST['desttime'];
  $stop              = $_POST['stop'];
  $duration          = $_POST['duration'];
  $freq              = $_POST['freq'];
  $flightnumber      = addslashes($flightnumber);
  $departure         = addslashes($departure );
  $destination       = addslashes($destination );
  $departurecity     = addslashes($departurecity);
  $destinationcity   = addslashes($destinationcity);
  $departuretime     = addslashes($departuretime);
  $arrivaltime       = addslashes($arrivaltime);
  $stop              = addslashes($stop);
  $duration          = addslashes($duration);
  $freq              = addslashes($freq);
  $sql = "INSERT INTO flights (flight_num, dept, dest, depticao, desticao, depttime, desttime, stops, duration, freq) VALUES (, $departure, $destination, $departurecity, $destinationcity, $departuretime, $arrivaltime, $stop, $duration, $freq)";
  if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 Flight Added...";
echo '<br>';
echo '<br>';
  }}}
  ?>

Link to comment
https://forums.phpfreaks.com/topic/61644-solved-mysql-query-error/
Share on other sites

try this as your query:

 

$sql = "INSERT INTO flights (flight_num, dept, dest, depticao, desticao, depttime, desttime, stops, duration, freq) VALUES ('', '".$departure, '".$destination."', '".$departurecity."', '".$destinationcity."', '".$departuretime."', '".$arrivaltime."', '".$stop."', '".$duration."', '".$freq."')";

try this as your query:

 

$sql = "INSERT INTO flights (flight_num, dept, dest, depticao, desticao, depttime, desttime, stops, duration, freq) VALUES ('', '".$departure, '".$destination."', '".$departurecity."', '".$destinationcity."', '".$departuretime."', '".$arrivaltime."', '".$stop."', '".$duration."', '".$freq."')";

 

I found the error... But now it gives me a syntax error with :

 

try this as your query:

 

$sql = "INSERT INTO flights (flight_num, dept, dest, depticao, desticao, depttime, desttime, stops, duration, freq) VALUES ('', '".$departure, '".$destination."', '".$departurecity."', '".$destinationcity."', '".$departuretime."', '".$arrivaltime."', '".$stop."', '".$duration."', '".$freq."')";

 

I found the error... But now it gives me a syntax error with :

 

try

$sql = "INSERT INTO flights (flight_num, dept, dest, depticao, desticao, depttime, desttime, stops, duration, freq) VALUES ('', '".$departure."', '".$destination."', '".$departurecity."', '".$destinationcity."', '".$departuretime."', '".$arrivaltime."', '".$stop."', '".$duration."', '".$freq."')";

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.