Jump to content

Undefined index: limit error in the whole code


Russia

Recommended Posts

Hey guys, Im getting an undefined index limit in the whole code.

 

This is my code:

 

<?php
session_start();
$_SESSION['prev_page'] = $_SERVER['REQUEST_URI'];
if (!session_is_registered('username')) {
    header("location:login.php");
}
?> 



<hr>

<style type="text/css">
table.gridtable {
  color:#333333;
  border-width: 1px;
  border-color: #666666;
  border-collapse: collapse;
        width: 100%;
}
table.gridtable th {
  border-width: 1px;
  padding: 1px;
  border-style: solid;
  border-color: #666666;
  background-color: #dedede;
}
table.gridtable td {
  border-width: 1px;
  padding: 1px;
  border-style: solid;
  border-color: #666666;
}

.valid {
  border-width: 1px;
  padding: 1px;
  border-style: solid;
  border-color: #666666;
  background-color: transparent;
}


</style>
</div>
<div class="newsJustify">
<script type="text/javascript">
   function checkall(delchk)
   {
      for (i = 0; i < delchk.length; i++)
      delchk[i].checked = true;
   }
</script>

<script type="text/javascript">
   function uncheckall(delchk)
   {
      for (i = 0; i < delchk.length; i++)
      delchk.checked = false;
   }
</script>



<script language="JavaScript">
function loadPage(list) {
  location.href=list.options[list.selectedIndex].value
}
</script>


<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("chat") or die(mysql_error());

if (isset($_POST['del'])) {
    for ($count = 0; $count < count($_POST["delchk"]); $count++) {
        $delete = $_POST["delchk"][$count];
        $query  = "DELETE FROM members_shouts WHERE id = '$delete'";
        $result = mysql_query($query);
        if (!$result) {
            die("Error deleting accounts! Query: $query<br />Error: " . mysql_error());
        }
    }
}

$data = mysql_query("SELECT * FROM `members_shouts`") or die(mysql_error());
$rows = mysql_num_rows($data);

$page_rows = $_GET["limit"];
if ($page_rows == '') {
    // no double quotes (int)
    $page_rows = 5;
} elseif ($page_rows == 'all') {
    $page_rows = $rows;
} else {
    $page_rows = $_GET['limit'];
    /* validate this */
}
if (!isset($_GET['pagenum'])) {
    $page = 1;
} else {
    $page = (int) $_GET['pagenum'];
}
?>

<?php
$max_pages = ceil($rows / $page_rows);
$last      = ceil($rows / $page_rows);
$pagenum   = ($page && $page > 0 && $page <= $last) ? $page : 1;
$max       = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows;
$data_p = mysql_query("SELECT * FROM members_shouts $max") or die(mysql_error());
?>





<?php
$result = mysql_query("SELECT * FROM members_shouts");
if (mysql_num_rows($result) > 0) {
?>



<span style="float: left;margin-left: 2px;">
<form>
<select name="file" size="1" onchange="loadPage(this.form.elements[0])" target="_parent._top">
            <option value="" <?php
    if ($_GET['limit'] == 0) {
        echo 'selected';
    }
?>>Select Limit</option>
            <option value="?limit=9" <?php
    if ($_GET['limit'] == 9) {
        echo 'selected';
    }
?>>9</option>
            <option value="?limit=15" <?php
    if ($_GET['limit'] == 15) {
        echo 'selected';
    }
?>>15</option>
            <option value="?limit=30" <?php
    if ($_GET['limit'] == 30) {
        echo 'selected';
    }
?>>30</option>
            <option value="?limit=all" <?php
    if ($_GET['limit'] == 'all') {
        echo 'selected';
    }
?>>All</option>
</select>
</form>
</span>

<span style="float: right;margin-top: 2px;margin-right: 2px;">
<center>
<?php
    if ($pagenum == 1) {
    } else {
        echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&limit={$_GET['limit']}'>First</a> ";
        echo " | ";
        echo " ";
        $previous = $pagenum - 1;
        $current  = $pagenum;
        echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&limit={$_GET['limit']}'>$previous</a> ";
        echo " | ";
    }
    echo "$pagenum";
    if ($pagenum == $last || $last == 0) {
    } else {
        $next = $pagenum + 1;
        echo " | ";
        echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&limit={$_GET['limit']}'>$next</a> ";
        echo " ";
        echo " | ";
        echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&limit={$_GET['limit']}'>Last</a> ";
    }
?>
</center>
</span>

<style type="text/css">
  .clear2 {
    clear:both;
    height:0px;
    overflow:hidden;
  }
</style>

  <div class="clear2"></div>
<hr>




<?php
    echo "<table class=\"gridtable\">
<thead>
    <tr>
        <th align=\"center\" scope=\"col\">user</th>
        <th align=\"center\" scope=\"col\">message</th>
        <th align=\"center\" scope=\"col\">when</th>
       <th align=\"center\" scope=\"col\">Delete?</th>
    </tr>
</thead>
<tbody>";
    echo "<form name = 'myform' action='' method='post'>";
?>




<?php
    while ($info = mysql_fetch_array($data_p)) {
        echo "<tr align=\"center\">";
        echo "<td class=\"valid\" >" . $info['user'] . "</td>";
        echo "<td class=\"valid\" >" . $info['message'] . "</td>";
        echo "<td>" . $info['when'] . "</td>";
        echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="' . $info['id'] . '" /></td>';
        echo "</tr>";
    }
    echo "</tbody>";
    echo "</table>";
    echo "<hr>";
    echo "<input type='submit' name = 'del' value='Delete Selected'></form>";
    echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>";
    echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>";
    echo "<hr>";
?>



<?php
} else {
    // No rows were found ...
    echo '<center>No logged accounts.</center><hr>';
}
?> 
</hr>

 

Im getting these errors and cant figure out at all how to fix them.

 

the reason is, is that you can set the limit of rows to show on one page, and that is set by the variable limit

 

it is used in 'localhost/admin?limit=5' That is 5 rows per page.

 

There is also one called 'localhost/admin?limit=all' that is to show all the rows in one page.

 

Im getting the errors:

 

Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 176

Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 179

Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 90

Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 130

Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 135

Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 140

Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 145

Notice: Undefined index: limit in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 150

 

I would be glad if someone could help me out by showing me how to set the limit when there is no GET used in the url.[/i]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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