Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/10/2012, 22:37
kingpioneer
 
Fecha de Ingreso: octubre-2012
Mensajes: 6
Antigüedad: 11 años, 6 meses
Puntos: 0
You have an error in your SQL syntax...

Hola
Estoy realizando mi primer página web por php y me topé con un error que llevo días sin poder solucionarlo, ojalá me puedan ayudar compañeros.
El error es el siguiente

Cita:
select * from records where id!=-1 or id= or id=14 or id=16 or id=8You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'or id=14 or id=16 or id=8' at line 1
Y mi código es:

Cita:
<?php require_once('/Connections/conex.php'); ?>
<?php
session_start();
$_SESSION['conex'][$_GET['recordID']]=$_GET['recordID'];

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title></title>

<link href="principall2.css" rel="stylesheet" type="text/css" />
<!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.thrColElsHdr #sidebar1, .thrColElsHdr #sidebar2 { padding-top: 30px; }
.thrColElsHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
</style>
</head>


<table width="100%" border="1">
<tr>
<td width="56%"><div align="center">Records</div></td>
<td width="12%"><div align="center">Price</div></td>
<td width="10%"><div align="center">Qt</div></td>
<td width="22%"><div align="center"></div></td>
</tr>

<?php
$cad="";
foreach($_SESSION['conex'] as $k)
{
$cad.=' or id='.$k;
}
$sql=' select * from records where id!=-1'.$cad;
echo $sql;
$re= mysql_query($sql) or die (mysql_error());
while ($f=mysql_fetch_array($re))

?><tr>
<td><?php echo $f("strrecord");?></td>
<td><?php echo $f("dblprecio");?></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

<p><a href="index.php">Continue shopping</a></p>
<!-- end #mainContent --></div>
</body>
</html>

¿Qué debo hacer para solucionarlo?
Gracias de antemano