Page 1 of 1

category manager

Posted: Thu Sep 01, 2011 4:29 am
by david_yg
If I run the following code:

Code: Select all


/* CATEGORY MANAGER  */
	  
	  // cek login
	  
if (!$_SESSION['login']){
		echo "Anda tidak berhak mengakses halaman ini.";
		exit();
	}

	//SIMPAN DATA
	if (isset($_REQUEST['simpan'])){
		$kategori = mysql_real_escape_string($_REQUEST['kategori']);
		$id = $_REQUEST['id'];
		
		if (empty($id))
			$sqlstr = "INSERT INTO kategori_berita(kategori) VALUES('".$kategori."')";
		else
			$sqlstr = "UPDATE kategori_berita SET kategori = '".$kategori."' WHERE id =".$id;
		
		$result = mysql_query($sqlstr) or die(mysql_error());
		
		$confirmation = ($result)? "Data telah tersimpan.":"Gagal menyimpan data.";
		$kategori = "";
		$id = "";
	}
	
	

The following errors appears, why is it?

Notice: Undefined variable: _SESSION in C:\xampp\htdocs\php_template2\category_manager.php on line 70
Anda tidak berhak mengakses halaman ini.

Re: category manager

Posted: Thu Sep 01, 2011 8:36 am
by genix2011
Hi,

you forgot to do an session_start(); on top of your script.

Greets.

Re: category manager

Posted: Thu Sep 01, 2011 8:52 am
by david_yg
Another errors:

Notice: Undefined index: login in C:\xampp\htdocs\php_template2\category_manager.php on line 71
Anda tidak berhak mengakses halaman ini.

Re: category manager

Posted: Thu Sep 01, 2011 8:55 am
by Celauran
That's not an error, it's a notice. It's just telling you that you're trying to access a variable that may not have been set.

Re: category manager

Posted: Tue Sep 06, 2011 3:02 am
by david_yg
How to set the variable? Where should I pass it from? what's the syntax?

line 71 if (!$_SESSION['login'])

error:
Undefined index: login in C:\xampp\htdocs\php_template2\category_manager.php on line 71

Re: category manager

Posted: Tue Sep 06, 2011 4:36 pm
by genix2011
Hi,

use the isset function.

Code: Select all

if(!isset($_SESSION['login']))
Greets.