0

Hello,

I just made my web in localhost, everything was just fine until I updates my xampp to newer version. And my web now is on a mess.

<br/>
	<div class="headerStyle">
		
	</div>
<?php
	$result = mysql_query("SELECT * FROM kategori_berita") or die(mysql_error());
	echo '<ul>';
	while ($data=mysql_fetch_array($result)){
		if ($_REQUEST['catid']==$data['id'])
			echo '<li style="color:#000;">'.$data['kategori'].'</li>';
		else
			echo '<li><a class="newsCategory" href="./?catid='.$data['id'].'">'.$data['kategori'].'</a><br/></li>';
	}
	echo '</ul>';
?>

here's the code and it shows me :
Notice: Undefined index: catid in C:\Program Files\xampp\htdocs\pbd\include\kategori_berita.php on line 9

I'm still new at PHP, so please if you could teach me I would appreciate it :twisted:
thanks!

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by GliderPilot
1

This happens when a variable isn't set properly. In this case it's your $_REQUEST variable. When using data pulled through REQUEST, POST, GET, or COOKIE you should always verify that is has a value prior to using it

i.e.

if (isset($_REQUEST['catid'])
{

  //Variable is set so do what you want with it

}
else
{

  //Variable is not set so toss error back to user

}

That being said it is generally advisable not to use $_REQUEST it is bad practice and opens a lot of security issues. Use the appropriate $_POST, $_GET, or $_COOKIE instead.

Edited by GliderPilot: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.