hello i have a running code the only question is the get function wont get the field i type here's my whole code




$searchText = htmlspecialchars ($_GET['q']);

$action = (isset($_REQUEST['action'])&& $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';

if($action == 'ajax'){

    include 'pagination.php'; //include pagination file

    //pagination variables
    $page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
    $per_page = 5; //how much records you want to show
    $adjacents  = 5; //gap between pages after number of adjacents
    $offset = ($page - 1) * $per_page;

    //Count the total number of row in your table*/
    $count_query   = mysql_query("SELECT COUNT(personid) AS numrows FROM persons");
    $row     = mysql_fetch_array($count_query);
    $numrows = $row['numrows'];
    $total_pages = ceil($numrows/$per_page);
    $reload = 'index.php';

        // basic SQL-injection protection

    //main query to fetch the data
        // query with simple search criteria
$query = mysql_query("SELECT * FROM persons WHERE FirstName LIKE '%" 
           . $searchText . "%' ORDER by RAND() LIMIT $offset,$per_page");

    //loop through fetched data

        while($result = mysql_fetch_array($query)){
        $id = $result['PersonID'];

                                      echo "<div class= content > ";

                                      echo"<img height=100 width=100 src='upload/". $result['Image'] ."'/>";
                                      echo "<font color='black'>". $result['FirstName']. "</font></br>";

                                      echo "</div>";

echo paginate($reload, $page, $total_pages, $adjacents);
} else{     

<html xmlns="http://www.w3.org/1999/xhtml">
<title>Simple Ajax Pagination With PHP And MySql</title>
<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
<link media="screen" href="style.css" type="text/css" rel="stylesheet">
<script type="text/javascript">

    function load(page){


<div id="loader"><img src="loader.gif"></div>

<div class="content"><form action='' method='POST'> <input type='text' name='q' /> <input type='submit' name='submit' value='Search' /> </p> </form></div>

<div class="outer_div"></div>



the error it shows is Notice: Undefined index: q in C:\xampp\htdocs\paging\index.php on line 7
but i have the form in the same page here's my pagination

when i change $searchText = htmlspecialchars ($_GET['q']);

to ` $searchText = 'ermel';

it works the only problem if it's not like that it don't heres a print screen
![9ba8006409794664521ac9ce8c2d298a](/attachments/large/4/9ba8006409794664521ac9ce8c2d298a.png "9ba8006409794664521ac9ce8c2d298a")

thanks for the comments and suggestions!

Member Avatar for Zagga

There are a couple of reasons you are getting an error.
Firstly, your form is using the method POST but you are trying to retrieve the value using GET.
Secondly (after you fix the first problem), $_GET['q'] isn't set until after you submit the form. Enclose the PHP in an if statement so it only executes if(isset($_GET['q']))

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.