Why am I getting these error and warning?
I'm getting the following warning and error when I run my php file:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a3763404/public_html/search.php on line 102
The concerned PHP code is:
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 '-20, 20' at line 1
echo "Oops! You didn't type anything to search. Please insert something to search";
// Include database connection settings
//-select the database to use
//-query the database table
$sql="SELECT Title, Post, Date FROM entries WHERE Title LIKE '%" . $name . "%' OR Post LIKE '%" . $name ."%' OR Date LIKE '%" . $name ."%'LIMIT $startResults, $resultsPerPage";
//-run the query against the mysql query function
echo "<p>" .$numrows . " Results found for " . stripslashes($name) . "</p>";
$numberOfPages = 100;
$resultsPerPage = 20;
$startResults = ($page - 1) * $resultsPerPage;
$numberOfRows = $numrows;
$totalPages = ceil($numberOfRows / $resultsPerPage);
$query = mysql_query("SELECT * FROM entries LIMIT $startResults, $resultsPerPage") or die ('Error: '.mysql_error ());
while ($output = mysql_fetch_array($query))
echo '<a href="selected_post.php?Index='.$output['Index'].'">' .$output['Title'].'</a><br>';
$halfPages = floor($numberOfPages / 2);
$range = array('start' => 1, 'end' => $totalPages);
$isEven = ($numberOfPages % 2 == 0);
$atRangeEnd = $totalPages - $halfPages;
if($totalPages > $numberOfPages)
if($page <= $halfPages)
$range['end'] = $numberOfPages;
elseif ($page >= $atRangeEnd)
$range['start'] = $totalPages - $numberOfPages + 1;
$range['start'] = $page - $halfPages;
$range['end'] = $page + $halfPages;
if($page > 1)
echo '<a href="?page='.($page - 1).'">«</a> ';
for ($i = $range['start']; $i <= $range['end']; $i++)
if($i == $page)
echo '<strong>'.$i.'</strong> ';
echo '<a href="?page='.$i.'">'.$i.'</a> ';
if ($page < $totalPages)
echo '<a href="?page='.($page + 1).'">»</a> ';
RE: Why am I getting these error and warning?
The PHP code is meant to receive input from a search form. The php in the search.php file (see below) should search for the inputted text in three columns on a table: Title, Post and Date. If it finds matches, it lists only the titles of the rows in which the word being searched has been found. If the searches are many, the first twenty appear on page 1, the next 20 on page 2 and so on. If no matches are found, the php code echoes "No matches found."
I have tried coming up with the following code but it isn't working as I'd want it to. First, I excluded the Date column from the searchable areas because the code was generating errors when I included Date column. Secondly, the php is listing every title of rows in my table.
I have not understood Arcticwarrio statement that "Date is a reserved word you'll need backsticks when referencing it `date`". What am I meant to do with the Date word?
Please help. Thank you.