Lukysimas Lukysimas - 1 month ago 20
MySQL Question

PHP admin system

I creating simple admin panel for myself , and i have a problem .
I inserted into mysql in "users" table - admin :

*CREATE TABLE IF NOT EXISTS `users` (
`username` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`admin` int(10) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;*

<?php

if(isset($_SESSION['user']['admin']))
{
if($_SESSION['user']['admin'] = '1')

{
echo "asasas";
}
}
else
{
echo "string";
}
?>

Answer

You are assigning here:

if($_SESSION['user']['admin'] = '1')

You need to use comparison here as:

if($_SESSION['user']['admin'] == '1')

(=) you can use it for assigning the value to variable.

(==) you can use it for comparison.

(===) you can compare the values along with DataType.

The most important part is that, you also need to use session_start() when you need to access $_SESSION values

You must need to learn about PHP Operator, follow the manual: http://php.net/manual/en/language.operators.php