pneudralics Posted November 3, 2008 Share Posted November 3, 2008 I'm testing out my file on wampserver and get the following error: 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 <?php include('c/connect.php'); include('header.php'); // Paging if(isset($_GET['page'])){ $page=$_GET['page']-1; }else{ $page=0; } $imagepath = WEBSITEURL.'images/gallery/'; $imagethumbnailpath = WEBSITEURL.'images/t/'; ?> <table width="800" bgcolor="#FFFFFF" align="center"><!--Start big table--> <tr> <td width="60%" valign="top" align="center"> <?php // Count All the items >> $q= "SELECT count(id) AS items_count FROM gallery;"; $r= mysql_query($q) or die (mysql_error()); $row = mysql_fetch_array($r,MYSQL_ASSOC); $items_count=$row['items_count']; // Count All the items << $q= "SELECT * FROM gallery ORDER BY id DESC LIMIT ".$page*$page_size.",".$page_size.";"; $r= mysql_query($q) or die (mysql_error()); if(mysql_num_rows($r)>0){ $current_colum=0; ?> <table> <?php while ($row = mysql_fetch_array($r,MYSQL_ASSOC)){ $current_colum++; if($current_colum==1){ ?> <tr> <?php } ?> <td valign="top"> <table bgcolor="#e4ecf0"> <tr> <td valign="top"> <a href="<?php echo $imagepath.$row['image']; ?>"><?php echo '<img src="'.$imagepath.$row['image'].'" width="150" height="150"' ?><?php echo " alt=\"$rowtitle\" /><br />"; ?></a> </td> </tr> </table> </td> <?php if($current_colum==3){ $current_colum=0; ?> </tr> <?php } }//End while if($current_colum!=0){ if($current_colum==1){ ?> <td> </td> <td> </td> <?php } if($current_colum==2){ ?> <td> </td> <?php } ?> </tr> <?php } ?> </table> <?php }// if(mysql_num_rows($r)>0){ // PAGING >> if ($items_count>$page_size) { $content.='<br />'; if ($page>0) { $content.='<a href="'.basename($_SERVER['PHP_SELF']).'?page='.($page).'"><b>Previous</b></a> '; } $content.='<b>'; for($z=0;$z<($items_count/$page_size);$z++) { if (($z>$page-$max_pages_to_show)&&($z<$page+$max_pages_to_show)) { if ($z==$page) { $content.=' '.($z+1).' '; } else { $content.=' <a href="'.basename($_SERVER['PHP_SELF']).'?page='.($z+1).'">'.($z+1).'</a> '; } } } if ($z>$page+1) { $content.='</b> <a href="'.basename($_SERVER['PHP_SELF']).'?page='.($page+2).'"><b>Next</b></a>'; } else { $content.='</b>'; } $content.='<br/><br/>'; echo $content; } // PAGING << ?> </td> <td width="20%" valign="top"> </td> </tr> </table><!--End big table--> Link to comment https://forums.phpfreaks.com/topic/131190-mysql-syntax-error-near-line-1/ Share on other sites More sharing options...
revraz Posted November 3, 2008 Share Posted November 3, 2008 Echo $q here, a variable is probably empty, since I don't see you set $page_size. $q= "SELECT * FROM gallery ORDER BY id DESC LIMIT ".$page*$page_size.",".$page_size.";"; You may also want to not repeat variable names. You used $q twice. Link to comment https://forums.phpfreaks.com/topic/131190-mysql-syntax-error-near-line-1/#findComment-681134 Share on other sites More sharing options...
Andy-H Posted November 3, 2008 Share Posted November 3, 2008 $q= "SELECT count(id) AS items_count FROM gallery>;<"; $r= mysql_query($q) or die (mysql_error()); $q= "SELECT * FROM gallery ORDER BY id DESC LIMIT ".$page*$page_size.",".$page_size.">;<"; $r= mysql_query($q) or die (mysql_error()); Why the semicolons inside the query string? Link to comment https://forums.phpfreaks.com/topic/131190-mysql-syntax-error-near-line-1/#findComment-681137 Share on other sites More sharing options...
revraz Posted November 3, 2008 Share Posted November 3, 2008 Nothing wrong with semi colons in the Query, it's a valid MySQL ending character. Link to comment https://forums.phpfreaks.com/topic/131190-mysql-syntax-error-near-line-1/#findComment-681145 Share on other sites More sharing options...
Andy-H Posted November 3, 2008 Share Posted November 3, 2008 Learn something new every day lol Link to comment https://forums.phpfreaks.com/topic/131190-mysql-syntax-error-near-line-1/#findComment-681151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.