I have the following codes:

$confirmation = ($result)? "Data telah terhapus.":"Gagal menghapus data.";
		}elseif ($_REQUEST['mode'] == 'edit'){
			$result = mysql_query("SELECT * FROM kategori_berita WHERE id=".$_REQUEST['id']) or die(mysql_error());
			$data = mysql_fetch_array($result);
			$id = $data['id'];
			$kategori = $data['kategori'];
		}
	}
	?>
<div align="center">
	<div style="width:700px;text-align:left;padding-top:25px;">
	<div class="pageTitle">Category Manager</div>
	<?php echo $confirmation; ?><br/>
	<form method="get" action="<?php $_SERVER['PHP_SELF'] ?>">

This error appears:

Category Manager

Notice: Undefined variable: confirmation in C:\xampp\htdocs\php_template2\category_manager.php on line 109


Line 109 is <?php echo $confirmation; ?><br/>

What's wrong with it? I thought I define it already.

Recommended Answers

All 3 Replies

$confirmation = ($result)? "Data telah terhapus.":"Gagal menghapus data.";

You are setting confirmation in if condition so it is giving warning when you tried to used unintialise variable.

so before your if statement you write

$confirmation="";
<?php if($confirmation != '' || $confirmation != null) : ?>
<?php echo $confirmation; ?><br/>
<?php endif; ?>

You can try like above perhaps.

The more recourse efficient method would be to use the following on line 109.

<?php echo (!isset($confirmation))?$confirmation='':$confirmation; ?><br/>
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.