Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undefined Index error on paging scripts

Status
Not open for further replies.

Kriekie

Technical User
Nov 21, 2004
10
ZA
Hi All

I have a simple db table containing fields for ID, Ref # and Image name. The Ref field is NOT a unique key field. Below is my php script. It displays the first record, but as soon as I click on the "next" button, I get the error "Undefined Index: Ref on....."

<?php
error_reporting(E_ALL);
@require_once("scripts/pager.php");
$p = new Pager;
$limit = 1;
$start = $p->findStart($limit);

@require("scripts/connect.php");
$T = $_REQUEST["Ref"];
$count = mysql_num_rows(mysql_query("SELECT * FROM images WHERE Ref = '$T'"));
$pages = $p->findPages($count, $limit);
$result = mysql_query(("SELECT * FROM images WHERE Ref = '$T' LIMIT ".$start.", ".$limit), $connection) or die(mysql_error());
$next_prev = $p->nextPrev($_GET['page'], $pages);
while ($display = mysql_fetch_array($result)) {
$ID=$display["ID"];
$Ref=$display["Ref"];
$Image=$display["Image"];
echo "<p>$next_prev</p>";
echo "<p><img border='0' src='photos/$Image'></p>";
?>



Thnx!
 
It's hard to say. You're referencing $_REQUEST['Ref'], which doesn't say a lot. In generally I strongly recommend use of the more specific superglobals, such as $_GET, $_POST, etc.

It is also difficult to advise you because I don't know what the nextPrev method of the Pager class is should output.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Its not error, its a notice. PHP is telling that it has not encountered the variable 'Ref' before...To avoid this notice there are two options

Use the @ symbol to supress the notice
Code:
$T = @$_REQUEST["Ref"];
or code for it
Code:
if (isset($_REQUEST["Ref"])){
  $T = @$_REQUEST["Ref"];
}//end if

Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top