Я пытаюсь настроить разные обращения с помощью пользователя и администратора, но я не могу понять, как заставить их выглядеть разными, я попытался установить tinyint в базе данных, где 1 - admin и 0 это пользователь, но я не думаю, что я сделал это правильно. (u нашел код для него где-то в другом месте), поэтому, если есть лучший способ, помощь будет наиболее оценена. заранее спасибо. php создание отдельного пользователя/admin login
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Homeowners Association</title>
</head>
<?php
if ($_SESSION['validUser'] == "yes")
//is this already a valid user?
{
//turn off PHP and turn on HTML
?>
<h1>Display Events Admin Options</h1>
<p><a href="insertEvent.html">Input New Events</a></p>
<p><a href="selectEventsProtected.php">List of Events</a></p>
<p><a href="logout.php">Logout</a></p>
<?php //turn off HTML and PHP
}
else
{
if (isset($_POST['submitLogin']))
//Was this page called from a submitted form?
{
$inUsername = $_POST['loginUsername'];
//pull the username from the form
$inPassword = $_POST['loginPassword'];
//pull the password from the form
include ('dbConnect.php');
//Connect to the database
$sql = "SELECT * FROM homeowners WHERE username = '" . $inUsername . "' AND password = '" . $inPassword . "'";
//this SQL command will only work if BOTH the username and password on the table
$result = mysqli_query($link,$sql) or die("SQL Error " . mysqli_error($link) . "<p>SQL String: $sql</p>");
if (mysqli_num_rows($result) == 1)
//If this is a valid user there should be ONE row only
{
$_SESSION['validUser'] = "yes";
//this is a valid user so set your SESSION variable
//turn off PHP and begin HTML
?>
<h1>Display Events Admin Options</h1>
<p><a href="insertEvent.html">Input New Event</a></p>
<p><a href="selectEventsProtected.php">List of Events</a></p>
<p><a href="logout.php">Logout</a></p>
<?php //turn off HTML and turn on PHP
}
else
//This is an invalid user not in the database
{
echo "<h3>Invalid username or password. Please try again.</h3>"; //sets error message
//display login form again with the error message.
//turn off PHP and begin HTML
?>
<form method="post" name="login" action="login.php" >
<p>Username: <input name="loginUsername" type="text" /></p>
<p>Password: <input name="loginPassword" type="password" /></p>
<p><input name="submitLogin" value="Login" type="submit" /> <input name="" type="reset" /> </p>
</form>
<?php //turn off HTML and turn on PHP
}//end of checking for a valid user
}//end of checking for a submitted page
else //This page was not submitted so the user needs to se the sign on form to continue
{
//display the login form in the area below
//turn off PHP and begin HTML
?>
<h1>Login to access website</h1>
<form method="post" name="loginForm" action="login.php">
<p>Username: <input name="loginUsername" type="text" /></p>
<p>Password: <input name="loginPassword" type="password" /></p>
<p><input name="submitLogin" value="Login" type="submit" /> <input name="" type="reset" /> </p>
</form>
<?php //turn off HTML and turn on PHP
}//ends if statement to check for form submit
}//end if checking for a valid user
//turn off PHP and begin HTML
?>
</body>
</html>
Я попытался с помощью:
$query = mysqli_query("SELECT type FROM homeowners WHERE username = '$user'");
$gettype = mysqli_fetch_assoc($query);
if($gettype["type"] == 0){
echo("user");
}
elseif($gettype["type"] == 1){
echo("admin");
}
, но я не знаю достаточно о TINYINT (который я поставил, чтобы напечатать) не знаю
это ответ с использованием tinyint или enum (который я не могу использовать, потому что база данных говорит, что каждый раз я пытаюсь сделать ошибку)? – Felicyia
этот ответ использует tinyint, можете ли вы опубликовать таблицу базы данных? –
Я не знал, как я отправил его на свой сервер как jpg http://felicyiamcclelland.com/introphp/homeowners/images/server.jpg – Felicyia