Web Hosting Talk







View Full Version : SQL syntax error....


renjith
03-10-2008, 12:47 AM
Please help me
This code shows an error message

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 '' at line 1

The code is given

<?php
include("config1.php");
$id=$_REQUEST['id'];
$q="Select SQL_CALC_FOUND_ROWS * from `vid_table` WHERE vid_id=$id";
$rs=mysql_query($q) or die(mysql_error());
while ($row=mysql_fetch_array($rs))
{
$cat = $row[2];
}

$ql="Select SQL_CALC_FOUND_ROWS * from `vid_table` WHERE vid_cat = '$cat'";

$rs1=mysql_query($ql) or die(mysql_error());
$i=0;
while ($row=mysql_fetch_array($rs1))
{
$id[$i] = $row[0];
$thum[$i] = "flvfiles/".$row[1];
$thumb[$i] = $thum[$i].'.png';
$fil[$i] = "flvfiles/".$row[1];
$file[$i] = $fil[$i].'.flv';
$cat[$i] = $row[2];
$i=$i + 1;
}
$i=$i-1;

?>

Here, the datatype $cat is VARCHAR.It shows the same error even when I give the value directly as this,

$ql="Select SQL_CALC_FOUND_ROWS * from `vid_table` WHERE vid_cat = 'new'";

renjith
03-10-2008, 02:25 AM
Sorry, It may be a problem in passing the value.

Andrew_I
03-10-2008, 05:02 AM
SQL_CALC_FOUND_ROWS is available starting at MySQL 4.0. What MySQL version do you use?

Xeentech
03-10-2008, 08:13 AM
Please help me
$id=$_REQUEST['id'];
$q="Select SQL_CALC_FOUND_ROWS * from `vid_table` WHERE vid_id=$id";


Would you please escape the $id. Or stop messing with PHP and use a framework that stops you shooting your self in the foot.

orbitz
03-10-2008, 11:52 AM
Sorry, It may be a problem in passing the value.

I would echo out the query statements to see if there is anything missing.

loty
03-13-2008, 03:34 AM
its better to wrote it like that :


$ql="SELECT SQL_CALC_FOUND_ROWS * FROM `vid_table` WHERE vid_cat = '".$cat."' ";