Error in SQL Syntax

Discussion in 'MySQL' started by joshakjohn, Jan 4, 2012.

  1. #1
    *Apologies but I've now solved it, turned out that in the airport names with "Int'l" it didn't like the " ' " so once that's been removed it works fine!*

    I have a slight issue which is when I go to 'book' a flight I get different errors depending on which one I attempt to book.

    It's strange because it works with some but about 1/4 of them don't.

    Here is the full code...

    <?phpinclude 'db.php';
    
    
    $id = mysql_real_escape_string($_GET['id']);
    
    
    mysql_select_db($database);
    $query_flights = "SELECT * FROM pilots WHERE pilot_id = '".$_SESSION['callsign']."'";
    
    
    mysql_select_db($database);
    $query_flights = "SELECT * FROM schedule WHERE id = '$id'";
    $flights = mysql_query($query_flights) or die(mysql_error());
    $row_flights = mysql_fetch_assoc($flights);
    $totalRows_flights = mysql_num_rows($flights);
    
    
    $q=mysql_query("SELECT * FROM airports WHERE ICAO = '{$row_flights['dep']}'");
    $a=mysql_fetch_array($q);
    $lat = $a['lat'];
    $lng = $a['lng'];
    
    
    $q1=mysql_query("SELECT * FROM airports WHERE ICAO = '{$row_flights['arr']}'");
    $a1=mysql_fetch_array($q1);
    $lat1 = $a1['lat'];
    $lng1 = $a1['lng'];
    
    
    $date = date("d/m/Y");
    
    
    $function = mysql_real_escape_string($_GET['function']);			
    if($function == "book_flight") { 
    $add_booking = sprintf( "INSERT INTO bookings ( pilot_id, flight_no, dep_icao, dep_apt, arr_icao, arr_apt, ac, date_added ) VALUES ('".$_SESSION['callsign']."', '".$row_flights['flight_no']."', '".$row_flights['dep']."', '".$row_flights['dep_apt']."', '".$row_flights['arr']."', '".$row_flights['arr_apt']."', '".$row_flights['ac']."', '$date')");   mysql_select_db($database);
    $Result1 = mysql_query($add_booking) or die(mysql_error()); 
    header( 'Location: index.php?page=operations/booking_list&bid=added');
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title><? echo $row_flights['flight_no']; ?> - Flight Information :: Virgin Australia Virtual </title>
        <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAqsNG2eOMUCPP19GdFG_b1xTQeDfXwNSTcnO36Vnfo80u7iZeXBTqQHzPH9quTqKwO42M--F8T7361A"
                type="text/javascript"></script>
    <script type="text/javascript"> 
    function initialize() {
    	if (GBrowserIsCompatible()) {
    		
    		// Setup map
            var map = new GMap2(document.getElementById("map_canvas"));
    		map.setMapType(G_PHYSICAL_MAP);
    		
    		// GUI
    		map.addControl(new GSmallMapControl());
      		map.addControl(new GScaleControl());
    		map.addControl(new GMapTypeControl());     
    		map.addMapType(G_PHYSICAL_MAP);
    		map.removeMapType(G_NORMAL_MAP);
    		map.removeMapType(G_HYBRID_MAP);
    		
     
    		// Display
    		var plotColour = "#ff0000";
    		var plotWidth = 2;
    		
    		// Key coordinates
    				coordDep = new GLatLng("<? echo $lat ?>", "<? echo $lng ?>");
    				coordDest = new GLatLng("<? echo $lat1 ?>", "<? echo $lng1 ?>");
    		
    		var bounds = new GLatLngBounds();
    		bounds.extend(coordDep);
    		bounds.extend(coordDest);
    		
    		// Icons
    		var iconBase = new GIcon();
    		iconBase.iconSize = new GSize(18, 18); 
        iconBase.shadowSize = new GSize(18, 18); 
        iconBase.iconAnchor = new GPoint(6, 8); 
     
    		// Dep icon
    		var iconDep = new GIcon(iconBase);
    		iconDep.image = "images/other/icon_dep.png";
    		// Dest icon
    		var iconDest = new GIcon(iconBase);
    		iconDest.image = "images/other/icon_arr.png";
     
     	 var polyOptions = {geodesic:true};
            var polyline = new GPolyline([
              new GLatLng("<? echo $lat ?>", "<? echo $lng ?>"),
    		  new GLatLng("<? echo $lat1 ?>", "<? echo $lng1 ?>")
    		  ], "#660066", 2, 1, polyOptions);
            map.addOverlay(polyline);
    		// Dep/Dest markers
    		markerDep = new GMarker(coordDep, {icon: iconDep});
    		map.addOverlay(markerDep);
    		
    		markerDest = new GMarker(coordDest, {icon: iconDest});
    		map.addOverlay(markerDest);
    		
    		// Centre		
    				map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
    
    
    	}
    }
    </script>
    </head>
    
    
      <body onload="initialize()" onunload="GUnload()">
      <table width="100%" border="0" cellspacing="0" cellpadding="5">
      <tr>
        <td colspan="4" class="roster_header">Flight Information</td>
      </tr>
      <tr>
        <td width="14%">Origin:</td>
        <td width="25%"><? echo $row_flights['dep_apt']; ?> (<? echo $row_flights['dep']; ?>)</td>
        <td width="15%">Destination:</td>
        <td width="46%"><? echo $row_flights['arr_apt']; ?> (<? echo $row_flights['arr']; ?>)</td>
      </tr>
      <tr>
        <td>Flight Number:</td>
        <td><? echo $row_flights['flight_no']; ?></td>
        <td>Arrival Time:</td>
        <td><? echo $row_flights['arr_time']; ?></td>
      </tr>
      <tr>
        <td>Dep Time:</td>
        <td><? echo $row_flights['dep_time']; ?></td>
        <td>Sched. Aircraft:</td>
        <td><? echo $row_flights['ac']; ?></td>
      </tr>
      <tr>
        <td>Duration</td>
        <td><? echo $row_flights['duration']; ?></td>
        <td>Route:</td>
        <td><? echo $row_flights['route']; ?></td>
      </tr>
      <tr>
        <td>Radio Callsign:</td>
        <td><? echo $row_flights['callsign']; ?></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
      <tr>
        <td width="57%" class="roster_header" >Route Map</td>
      </tr>
      <tr>
        <td><div id="map_canvas" style="width: 100%; height: 500px"></div></td>
      </tr>
      <td align="center"><a href="index.php?page=operations/flight_info&function=book_flight&id=<? echo $row_flights['id']; ?>"><img src="images/book.png" border="0" /></a></td>
      </tr>
    </table>
    
    
    </body>
    </html>
    Code (markup):
    Initially I thought it was just flights that originated at Cairns YBCS but then I thought it was for flights arriving into Brisbane YBBN but there doesn't seem to be any pattern and I have no idea what's causing it so any help would be appreciated! :D
     
    Last edited: Jan 4, 2012
    joshakjohn, Jan 4, 2012 IP