Jump to content

Undifined Index Error - Please help!


johnmorris2801

Recommended Posts

Hi I have done a website in php, and mysql. it works fine at home on my apache server, but when uploaded to my service provider i get the following error:

Notice: Undefined index: p in /var/www/shared/a/n/www.andrewparkinson.com/inprint.php on line 16

 

 

Please see below code from this page.

 

<?php

include ("include/db.php");

?>

<?php

 

  $rcperpage = "12";

$getall = mysql_query("Select name from images where category1 = 'frontcovers'");

$numimages = mysql_num_rows($getall);

 

 

$numpages = $numimages / $rcperpage;

$numpages = ceil($numpages);

 

#Get Page number querystring

 

$pagenum = $_GET['p'];                                    [LINE 16]

if ($pagenum == ""){

$pagenum = "1";

}

 

#Calculate mysql limit, 6 images per page

 

if ($pagenum == ""){

$lowerlimit = "0";

$upper = $lowerlimit + 12;

}

else{

$lowerlimit = $pagenum * $rcperpage - $rcperpage;

$upper = $lowerlimit + 12;

}

 

 

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title></title>

<link href="css/layout.css" rel="stylesheet" type="text/css" />

 

</head>

<script type="text/javascript" src="js/prototype.js"></script>

<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>

<script type="text/javascript" src="js/lightbox.js"></script>

 

 

 

</script>

<body>

<div class="maincontainer">

  <div class="header">

    <p>in print</p>

  </div>

  <!--End Header-->

  <div class="sub_header">

    <h5> </h5>

    <h3> </h3>

    <div class="pages">

      <p>page: <?php

$i = 1;

while ($i <= $numpages) {

if($i == $pagenum){

echo "<b><a href=\"?p=" . $i . "\">" . $i . "</a></b>" . " ";}

else{

  echo "<a href=\"?p=" . $i . "\">" . $i . "</a>" . " ";}

$i++;

}

 

  ?></p>

    </div>

    <!--End pages-->

  </div>

  <!--End Sub Header-->

  <div class="nav">

    <ul>

      <li><a href="index.html">home ></a></li>

      <li><a href="biography.html">biography ></a></li>

      <li><a href="galleries.html">galleries ></a></li>

      <li class="onstate"><a href="inprint.php">in print ></a></li>

      <li><a href="news.html">news ></a></li>

      <li><a href="latest.html">latest images ></a></li>

      <li><a href="wild.html">wild nature ></a></li>

      <li><a href="contact.html">contact ></a></li>

    </ul>

    <div class="nav_footer">

<img src="images/Andrew Parkinson Logo for web.jpg" alt="logo" />

    </div>

  </div>

  <!--End Nav-->

  <div class="content">

  <div class="four_col1">

  <?php

  $count = 0;

  $getimages = "Select * from images where category1 = 'frontcovers' order by name LIMIT $lowerlimit, $rcperpage";

  $result = mysql_query($getimages);

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

 

  echo "<a title=\"" . $row['longdesc'] . "\" ><img title=\"" . $row['name'] . "\" width=\"145\" height=\"145\" border=\"0\" src=\"" . $row['smalllocation'] . "\"></a>";

  $count++;

  if ($count == 4 or $count == 8 or $count == 12){

  echo "</div><div class=\"four_col1\">";

  }

 

 

 

  }

 

  ?>

</div>

    <!--End four col-->

  </div>

  <!--End Content-->

  <div class="clear">

    <p> </p>

  </div>

</div>

<!--End Maincontainer-->

</body>

</html>

 

 

 

 

I would appreciate any help as this is driving me mad!.

 

Many thanks

 

Link to comment
https://forums.phpfreaks.com/topic/183588-undifined-index-error-please-help/
Share on other sites

that'd be because you have error reporting turned off in your php.ini file (on your localhost).

 

the error is telling you that p has not been defined.  if you were to attach:

 

?p=5

 

to the end of your URL, that error would go away.

 

change:

$pagenum = $_GET['p'];

 

to:

$pagenum = (isset ($_GET['p']) ? (int) htmlentities ($_GET['p']) : '');

Archived

This topic is now archived and is closed to further replies.

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