I appreciate anyone taking a fresh look as I am stuck with a seemingly simple functionality. header.php has 2 search fields and a search button. The form action invokes pagination.php that runs the query and paginates the results. The problem is that the form fields are not stored in session variables. Only the form fields, session variables work in login script and with hard-coded values.
Here is the form from header.php (with some debugging statements):
<form action="http://my1shop.uk/phpmarketplace/customer/pagination.php" method="post" class="searchform">
<input name="searchstring" class="textbox" type="text" placeholder="search string"/>
<input name="postcode" class="textbox" type="text" placeholder="postcode"/>
<input name="submit" class="submit" value="Search" type="submit" />
<?php
session_start();
//unset($_SESSION['test']);
$_SESSION['test']= 'Testsearch';
if (isset($_POST['submit'])) {
$_SESSION['search_string'] = $_POST['searchstring'];
$_SESSION['zip3'] = substr($_POST['postcode'],0,3);
$_SESSION['test2'] = 'Test2';
}
?>
</form>
Here is the first part of pagination.php (before SQL and pagination):
<?php
//error_reporting(E_ALL); ini_set('display_errors', 'On');
include_once '../config.php'; // has session_start() in it
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM forsale_content";
$result = dbQuery($sql) ;
$r = dbFetchRow($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 5;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
$keywords = $_SESSION['search_string'];
$zip = $_SESSION['zip3'];
$search = $_POST['searchstring'];
//$keywords = $_POST['searchstring'];
echo "pagination:" . $_SESSION['test'];
echo "test2:" . $_SESSION['test2'];
echo "zip:" . $_SESSION['zip3'];
echo strlen($keywords) ;
echo "search:" . $search;
if( $keywords == "")
{
echo "<div align=\"center\"><b>You did not enter a searchstring.</b></div>";
}
The result is "You did not enter a searchstring" and $keywords and $zip have no value (with error ON it says indexes 'search_string' and 'zip3' undefined).
However 'test' has correct value and if "if (isset($_POST['submit']))" is commented out in header.php - 'test2' also gets a value. But not the other 2 variables where values should be assigned from the form on submit. When I change form method to GET, I can see the field value picked up.
Have read all relevant articles, tried different browsers, checked for quotes, brackets etc. but ran out of ideas...