Good day.

The problem is as follows:

It is necessary to obtain from the users table the value of the group field, and if the value is 1, then load the menu template for the user, and if the value is 2, then load the menu template for the admin. Either incorrectly form a request, or there is some kind of catch.

Code about the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <?php session_start(); include ("bd.php"); $result = mysql_query("SELECT group FROM users"); $user_group = mysql_fetch_row($result); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Заказ комплексных обедов с доставкой</title> <link rel="stylesheet" href="css/style.css" type="text/css" /> </head> <body> <?php require 'tpl/sablon.php'; if ($user_group = 1) { require 'bloks/menu.php'; } if ($user_group = 2) { require 'bloks/menu2.php'; } ?> <div id="content"> <h1>Вход на сайт</h1> <form action="testreg.php" method="POST"> <p> <label>Ваш логин<br></label> <input name="login" type="text" size="15" maxlength="15"> </p> <p> <label>Ваш пароль<br></label> <input name="password" type="text" size="15" maxlength="15"> </p> <p> <input type="submit" name="submit" value="Войти"> <a href="reg.php">Зарегистрироваться</a> </p> </form> <br> <?php if (empty($_SESSION['login']) or empty($_SESSION['id'])) { echo "Вы вошли на сайт, как гость<br><a href='#'>Эта ссылка доступна только зарегистрированным пользователям</a>"; } else { echo "Вы вошли на сайт, как ".$_SESSION['login']."(<a href='exit.php'>выход</a>)<br>"; } ?> </div> </body> </html> 
  • @Samurai, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Vitalina

1 answer 1

Here's your class the right example for working with the database

  include 'registry.php'; class DataBase { public function Connect() { try { $user = 'ПОЛЬЗОВАТЕЛЬ_БД'; //! $dbname = 'ИМЯ_БД'; //! $pass = 'ПАРОЛЬ'; //! $options = array( PDO:: MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'); $con = Registry::set('DBH', new PDO("mysql:host=localhost;dbname=" . $dbname . "", $user, $pass, $options)); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); // репортим ошибки } catch (PDOException $e) { echo $e->getMessage(); } } public function Disconnect() { $DBH = null; } } class MyClassForTable extends DataBase { public static function LoadFromTable(){ $DBH = Registry::get('DBH'); $STH = $DBH ->prepare( "SELECT * FROM ИМЯ_ТАБЛИЦЫ" ); // заменить на имя таблицы $STH->execute(); $result = $STH->fetchAll(); return $result; } } $db = new database(); // Создаем экземпляр класса $db->Connect(); // Вызываем метод для подключения $data = MyClassForTable::MyClassForTable(); // Забираем данные из таблицы в $data var_dump($data); // Выводим $data $db->Disconnect(); // закрываем соединение 

The registry pattern code (registry.php) can be collected here. http://ideone.com/Yag3ki