Jump to content

Recommended Posts

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 DB
mysql_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 tearm
If($SearchString == "") $SearchString=$_GET["SearchString"]; // Get the search tearm
If($SearchString == "") {
Echo"Nothing to Search For";
exit();
}
$page=$_GET["page"]; //Get the page number to show
If($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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.