PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
david_yg
Forum Newbie
Posts: 20 Joined: Tue Aug 09, 2011 10:19 am
Post
by david_yg » Thu Sep 01, 2011 4:29 am
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.
genix2011
Forum Commoner
Posts: 74 Joined: Tue Aug 02, 2011 4:00 pm
Post
by genix2011 » Thu Sep 01, 2011 8:36 am
Hi,
you forgot to do an session_start(); on top of your script.
Greets.
david_yg
Forum Newbie
Posts: 20 Joined: Tue Aug 09, 2011 10:19 am
Post
by david_yg » Thu Sep 01, 2011 8:52 am
Another errors:
Notice: Undefined index: login in C:\xampp\htdocs\php_template2\category_manager.php on line 71
Anda tidak berhak mengakses halaman ini.
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Thu Sep 01, 2011 8:55 am
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.
david_yg
Forum Newbie
Posts: 20 Joined: Tue Aug 09, 2011 10:19 am
Post
by david_yg » Tue Sep 06, 2011 3:02 am
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
genix2011
Forum Commoner
Posts: 74 Joined: Tue Aug 02, 2011 4:00 pm
Post
by genix2011 » Tue Sep 06, 2011 4:36 pm
Hi,
use the
isset function.
Greets.