I have coded to display mysql results.but when I enter mysql login details to onefile (config.php) I'm getting this 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 Code (markup): Here the index.php <? include("config.php"); mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error()); mysql_select_db($db) or die("ERROR DB:".mysql_error()); $p = $_GET['p']; if(empty($p)) { $p = 1; } $limits = ($p - 1) * $max; //view the news article! if(isset($_GET['act']) && $_GET['act'] == "view") { $id = $_GET['id']; $sql = mysql_query("SELECT * FROM data WHERE id = '$id'"); while($r = mysql_fetch_array($sql)) { $title = $r['url']; $id = $r['id']; } }else{ //view all the news articles in rows $sql = mysql_query("SELECT * FROM data order by id DESC LIMIT ".$limits.",$max ") or die(mysql_error()); //the total rows in the table $totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM data order by id DESC"),0); //the total number of pages (calculated result), math stuff... $totalpages = ceil($totalres / $max); //the table while($r = mysql_fetch_array($sql)) { $title = $r['title']; $author = $r['id']; echo "<table border='0' cellspacing='0' cellpadding='0'> <tr> <td><span style='text-decoration: none'><div align='center'><img src='$title' alt='Sinhala Comments - Suduputha.Com' border='0' /></span></div></td> </tr> <tr> <td><div align='center'><textarea name='textarea' cols='37' rows='4' onmouseover='this.focus()' onfocus='this.select()'> <a href= \"http://www.suduputha.com\" target=\"_blank\"><img src=\"$title\" alt=\"Sinhala Comments - Suduputha.Com\" border=\"0\"></a><b><table border=\"1\" cellspacing=\"1\" bgcolor=\"#FFFFFF\" style=\"border-collapse: collapse\" bordercolor=\"#000000\" id=\"table1\"><tr><td><font face=\"Tahoma\" style=\"font-size: 8pt; font-weight: 700\"><a target=\"_blank\" href=\"http://www.Suduputha.com\"><font color=\"#000000\"><span style=\"text-decoration: none\">Get Free Sinhala Comments</span></font></a></font></td></tr></table></textarea></div><br><br>"; } //close up the table echo "<div align='center'>"; for($i = 1; $i <= $totalpages; $i++){ //this is the pagination link echo "<a href='index.php?p=$i'>$i</a> | "; } echo"</div>"; } ?> PHP: Here the config.php <? //Database Settings $host = "localhost"; //your sql host, usually 'localhost' $user = "****"; //username to connect to database $pass = "****"; //password to connect to database $db = "****"; //the name of the database $max = 5; //amount of articles per page. change to what to want ?> PHP:
are you triggering any of your "act" functions, or is it giving you this error in any location? Also, instead of $totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM data order by id DESC"),0); Code (markup): use $totalres = mysql_result("SELECT COUNT(id) AS tot FROM data order by id DESC"); Code (markup): but i may be wrong, but thats just how i do it. Also, in your querys, i suggest adding the ` char around your field names, such as SELECT * FROM `data` ORDER BY `id`, etc.
echo() alone will not tell you what is wrong with your query, but, you can echo your query and then place it in phpmyadmin and try to run it there, and that will tell you if you have an error
Yeah, sorry should've been more specific phpMyAdmin is a good tool to check for SQL syntax errors. Check your query when it is echoed to see if there are any missing bits - variables from a form for example - which might not be being put into the query.