Jump to content

Please help me


achintha

Recommended Posts

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

 

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>";
}
      ?>

 

 

 

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

?>

Link to comment
https://forums.phpfreaks.com/topic/108143-please-help-me/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.