Venkatesh Posted November 11, 2006 Share Posted November 11, 2006 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 '5' at line 1[b]Code: [/b] <?//Connect to DBmysql_connect("localhost","user","pass") or die("Unable to connect to SQL server");mysql_select_db("Web") or die("Unable to SELECT DB");$pagenum = 5; //Number of results per page$SearchString=$_POST["SearchString"]; // Get the search tearmIf($SearchString == "") $SearchString=$_GET["SearchString"]; // Get the search tearmIf($SearchString == "") {Echo"Nothing to Search For";exit();}$page=$_GET["page"]; //Get the page number to showIf($page == "") $page=1; //If no page number is set, the default page is 1//Get the number of results$SearchResult=mysql_query("SELECT * FROM Hyd_Contacts") or die(mysql_error());$NumberOfResults=mysql_num_rows($SearchResult);//Get the number of pages$NumberOfPages=ceil($NumberOfResults/$pagenum);$SearchResult=mysql_query("SELECT * FROM Hyd_Contacts" . ($page-1)*$pagenum . ",$pagenum") or die(mysql_error());While($row = mysql_fetch_object($SearchResult)) {Echo $row->ArticleTitle . "<BR>";}$Nav="";If($page > 1) {$Nav .= "<A HREF=\"Search.php?page=" . ($page-1) . "&SearchString=" .urlencode($SearchString) . "\"><< Prev</A>";}For($i = 1 ; $i <= $NumberOfPages ; $i++) {If($i == $page) {$Nav .= "<B>$i</B>";}Else{$Nav .= "<A HREF=\"Search.php?page=" . $i . "&SearchString=" .urlencode($SearchString) . "\">$i</A>";}}If($page < $NumberOfPages) {$Nav .= "<A HREF=\"Search.php?page=" . ($page+1) . "&SearchString=" .urlencode($SearchString) . "\">Next >></A>";}Echo "<BR><BR>" . $Nav;?> Link to comment https://forums.phpfreaks.com/topic/26914-php-error-message/ Share on other sites More sharing options...
wildteen88 Posted November 11, 2006 Share Posted November 11, 2006 Its not a PHP error by a MySQL error.One of you queries has an error which MySQL has reported.From looking at your code the error is coming from this query:[code]$SearchResult=mysql_query("SELECT * FROM Hyd_Contacts" . ($page-1)*$pagenum . ",$pagenum") or die(mysql_error());[/code]Change the above query to this:[code=php:0]$SearchQuery = "SELECT * FROM Hyd_Contacts" . ($page-1)*$pagenum . ", $pagenum)";$SearchResult = mysql_query($SearchQuery) or die("Unable to perform query<br />\n" . $SearchQuery . "<br /><br />" . mysql_error());[/code]Now re run your script again. Post the full error message it returns here. Link to comment https://forums.phpfreaks.com/topic/26914-php-error-message/#findComment-123093 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.