Forum Moderators: coopster

Message Too Old, No Replies

Help with a little error in a php file

I'm new to php and the phper has gone on hols

         

wintercornuk

10:41 am on Jan 7, 2005 (gmt 0)

10+ Year Member



I've been involved in designing a booking system for a hotel. I've mostly done the design and front end, whilst my colleague has done the back end with php and sql. He's gone on holiday for a couple of weeks and this new, untested system is failing on ths one page.

My knowledge is not enough to fix it, can anyone here help?

It comes up with the following error:

"error 1064: 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"

Code is as follows:

<?php
session_start();
include_once("db_functions.ins");
include_once("asset.php");
$total=0;
$dateFormat="%D %b %Y";
$now=getdate();
//header('Content-Type: application/x-msexcel');
//header('Content-Disposition: attachment; filename=\"Invoice.xls\"');
$sql="select * from asset where assetID=".$_REQUEST['clientID'];
$r=db_query($sql);
$select=$r[0];
echo "<html><body><table border=1>";
$sql="select t1.* from asset t1 where t1.deleted is null and t1.linkID=".$select['assetID'];
//echo $sql;
$classes=db_query($sql);
echo "<tr><td colspan=".(count($classes)*3)." align=right>company name<br>address 1, <BR>address 2, <BR>address 3, <BR>address 4, <BR>address 5</td></tr>\n";
echo "<tr><th colspan=".(count($classes)*3).">Register</th></tr>\n";
echo "<tr><td>Client Name</td><td colspan=4>".$select['name']."</td></tr>\n";
echo "<tr><td>Classes</td><td colspan=".(count($classes)*3).">".count($classes)."</td></tr>\n";

if(count($classes)) {
for($j=0;$j<count($classes);$j++) {
$sql="select t1.*, DATE_FORMAT(t2.date, '%D %b %Y %r') bDate, DATE_FORMAT(t2.startDate, '%D %b %Y %r') bStartDate, DATE_FORMAT(t2.endDate, '%D %b %Y %r') bEndDate, t2.qty, t2.clientID, t2.pending from asset t1 left join booking t2 on t1.assetID = t2.clientID where t2.deleted is null and t2.typeID=3 and t2.roomID=".$classes[$j]['assetID'];
//echo $sql."<BR>";
$assoc=db_query($sql);
$classes[$j]['classes']=$assoc;
if($max<count($assoc))$max=count($assoc);
}
for($i=-2;$i<$max;$i++) {
echo "<tr>";
for($j=0;$j<count($classes);$j++) {
if($i==-2)echo "<th colspan=3>".$classes[$j]['name']."</th>";
else if($i==-1)echo "<th>Name</th><th>Status</th><th>Date</th>";
else {
$class=$classes[$j]['classes'];
echo "<td>".$class[$i]['name']."</td><td>".$class[$i]['pending']."</td><td>".$class[$i]['bDate']."</td>";
}
}
echo "</tr>";
}
}

echo "</table></body></html>";
?>

dreamcatcher

11:24 am on Jan 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

A couple of your database queries need a slight alteration:

For example this:

$sql="select * from asset where assetID=".$_REQUEST['clientID'];

Needs to be this:

$sql="select * from asset where assetID='".$_REQUEST['clientID']."';

Note the single and double quotes in the query.

assetID='".$_REQUEST['clientID']."';

Your other queries need to be the same. Hope that helps.

dc

wintercornuk

12:04 pm on Jan 7, 2005 (gmt 0)

10+ Year Member



Thanks for the input. I've tried it an now it gives me a parse error on line 14. I can't seem to figure that one out!

johnt

2:05 pm on Jan 7, 2005 (gmt 0)

10+ Year Member



I think that you need another double quote at the end of the line. It should be

$sql="select * from asset where assetID='".$_REQUEST['clientID']."'";

Hope that does it.

John

dreamcatcher

5:29 pm on Jan 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ah, yep, well spotted john. That is indeed correct.