Results 1 to 2 of 2

Thread: PHP Error

  1. #1
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP Error

    Hello I am getting the following php Error
    PHP Code:

    <?
    $type
    =$_POST['type'];
    if(
    $type=="PASS/ARR"){
        
    $arr_dep="ARR";
        
    $cargo_pass="PASS";
    }
    if(
    $type=="PASS/DEP"){
        
    $arr_dep="DEP";
        
    $cargo_pass="PASS";
    }
    if(
    $type=="CARGO/ARR"){
        
    $arr_dep="ARR";
        
    $cargo_pass="CARGO";
    }
    if(
    $type=="CARGO/DEP"){
        
    $arr_dep="DEP";
        
    $cargo_pass="PASS";
    }
    $db_host="***************";
    $db_user="**************";
    $db_pwd="**********";
    $db_name="************";

    $db mysql_connect ($db_host$db_user$db_pwd) or die ("Impossibile connettersi al DB");
    mysql_connect ($db_host$db_user$db_pwd) or die ("Impossibile connettersi al DB");
    mysql_select_db ($db_name$db) or die ("Impossibile selezionare il DB");
    $query "    SELECT * FROM `sia` WHERE `arr_dep`='$arr_dep' , `cargo_pass`='$cargo_pass' ";
    $result mysql_query ($query$db)or die('Error in query: '.mysql_error()); 
        while (
    $line mysql_fetch_array ($resultMYSQL_ASSOC))
          {
    ?>

      <tr  height="30">
          
          <td><div align="center" class="style1"><b> <img style="margin-left:1px; " src="http://www.simmiles.com/asiava/SIA/logo/<? echo $line['airline_icao'?>.gif" alt="Logo Not Found"/>
                                                                      
     </b></div></td>

          <td><div align="center"><? echo $line['dep_icao']; ?></div></td>

          <td  ><div align="center"><? echo $line['arr_icao']; ?></div></td>
     <td><div align="center"><? echo $line['dep_time']; ?></div></td>
     <td  ><div align="center"><? echo $line['arr_time']; ?></div></td>
     <td><div align="center"><? echo $line['flight']; ?></div></td>
     <td ><div align="center"><? echo $line['aircraft']; ?></div></td>
     <td><div align="center"><? echo $line['airline_name']; ?></div></td>

    <?
    $avaible
    =$line['avaible'];
    if (
    $avaible=="YES"){ ?>
        


    <td><div align="left" class="style1"><b>   <a  href="book_flight.php?id=<? echo $line['id'?>" >Book</a> </b></div></td>


    <?
    }else{


    ?>
     


    <td><div align="left" class="style1"><i>   Booked</i></div></td>

    <?

    }
       
    ?>
       





     <?
          
    }
        
    ?>
          </table>

    <br />
    I get the following error
    PHP Code:
    Error in queryYou have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near ' `cargo_pass`='PASS'' at line 1 
    Any Ideas?

    I tried takeing out MYSQL_ASSOC But it did not work. I tried taking out `arr_dep`='$arr_dep' OR `cargo_pass`='$cargo_pass' and i works. What can I do next. I need both in there.
    Last edited by SimMiles; 06-19-2009 at 05:04 AM.

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Your problem is in this line, you are trying to select records if 2 fields match a value, this is called a conditional query and as such you need to use conditional operators

    PHP Code:
    $query "    SELECT * FROM `sia` WHERE `arr_dep`='$arr_dep' , `cargo_pass`='$cargo_pass' "
    Change the line to this

    PHP Code:
    $query "    SELECT * FROM `sia` WHERE `arr_dep`='$arr_dep' && `cargo_pass`='$cargo_pass' "
    A comma is not a conditional operator, you can use the comma as part of the ORDER BY part of a query to order by 2 or more fields.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •