please help me. this my trouble
Notice: Undefined index: p in C:\wamp\www\index.php on line 7
and soure

<?php
session_start ();
include ("function.php");
$title = "Trang chủ";
include ("header.php");

$p_now = intval($_GET ['p']);
$total = mysql_result ( mysql_query ( "SELECT COUNT(id) FROM baiviet WHERE kieu='post'" ), 0 );
$numofpages = $total / $pp;

if ($p_now<=0) {
	$page = 1;
} else {
	if($p_now <= ceil($numofpages))
		$page = $p_now;
	else
		$page = 1;
}

$limitvalue = $page * $pp - ($pp);
$query = "SELECT * FROM baiviet WHERE kieu='post'  ORDER BY id DESC LIMIT $limitvalue, $pp ";

$result = mysql_query ( $query );
while ( $row = mysql_fetch_array ( $result ) ) {
	?>
<br />
<div class="check"><a href="baiviet.php?id=<?=$row ['id'];?>"><?=$row ['tieude'];?> :</a></div>
<div><a href="upload/image/<?=$row ['hinhanh'];?>" class="preview"
	title="<?=$row ['tieude'];?>"><img
	src="upload/image/thumbs/<?=$row ['hinhanh'];?>" border="0"
	align="left" /></a>
<p><b>Lượt xem :</b> <?=$row ['view'];?><br />
<b>Ngày gửi :</b> <?=date ( 'd/m/Y \l\ú\c H:i:s', $row ['thoigian'] );?><br />
<b>Chuyên mục :</b> <a
	href="chuyenmuc.php?id=<?=$row ['catID'];?>"><?=getparentname ( $row ['catID'] );?></a><br />
<b>Tag :</b> <?=$row ['tag'];?><br />


<p><?=$row ['gioithieu'];?><a href="baiviet.php?id=<?=$row ['id'];?>">[ Chi tiết ...]</a></p>

</div>
<div class="clear"></div>


<?php
}
echo "<div class=\"center\">";
page_div ( "?p=%d_pg", "10", ceil ( $numofpages ), $page );
echo "</div>";
mysql_close ();
include ("footer.php")?>

==========================================
Notice: Undefined index: username in C:\wamp\www\header.php on line 37
this code

<?php
if (checkadmin ( $_SESSION ['username'] ) && $_GET ['page'] == 'addpost' || $_GET ['page'] == 'editpost') {
	?>

Dani AI

Generated

Two PHP notices were triggered by reading array keys that were not set (the pagination key from GET and the username from SESSION). was on the right track advising a presence check. The short-term aim is to stop the notices; the long-term aim is to validate and fail-safe inputs so the app remains correct and secure.

For the page number prefer validation over blind casting. Using the filter API both checks presence and enforces numeric input, with a clear fallback when the value is missing or invalid. See the PHP manual for filter_input for details: filter_input.

For the header notice avoid calling permission helpers with an unset session value and avoid comparing an unset GET key directly. First ensure the session key exists, then check the page key. Group the boolean tests so logic is unambiguous (operator precedence can change outcomes — see operator precedence). A safe pattern is to check existence, validate, then perform the role/test.

Other practical checks and tips:

  • Confirm the pagination page-size variable is defined and nonzero before dividing (an unset or zero page-size causes warnings or division errors).
  • Keep error reporting enabled during development; fixing notices is better than hiding them. See error_reporting.
  • Plan to migrate away from old mysql_* calls (they were removed in newer PHP); use mysqli or PDO for prepared queries and better compatibility. Guidance in the PHP docs: mysql_query.

Summary: apply presence checks, validate inputs, use clear grouped logic for conditionals, and sanitize/migrate database calls. That addresses the immediate notices and makes the code more robust going forward — thanks to for the nudge, and congrats to for getting this moving in the right direction.

Recommended Answers

All 3 Replies

Replace your line 7 with

$p_now=0;
if(isset($_GET['p']) && !empty($_GET['p'])
     $p_now = intval($_GET ['p']);

Use code tags to post your code

Replace your line 7 with

$p_now=0;
if(isset($_GET['p']) && !empty($_GET['p'])
     $p_now = intval($_GET ['p']);

Use code tags to post your code

thanhks :*

Mark this thread as solved if your problem solved

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.