Log in

View Full Version : PHP Error



SimMiles
06-19-2009, 04:45 AM
Hello I am getting the following php Error



<?
$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 ($result, MYSQL_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
Error in query: 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 ' `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.

forum_amnesiac
06-19-2009, 06:29 AM
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


$query = " SELECT * FROM `sia` WHERE `arr_dep`='$arr_dep' , `cargo_pass`='$cargo_pass' ";

Change the line to this


$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.