Answer the question
In order to leave comments, you need to log in
How to display a message about successful or unsuccessful authorization on the site?
The essence of the task is that you need to display a message about whether the login and password are entered correctly or not. When you press the "enter" button, the program does not react in any way, what could be the problem?
<?php
function function_alert($msg)
{
echo "<script type='text/javascript'>alert('$msg');</script>";
}
$login = 'Lane';
$password = 'admin';
if(isset($_POST['btn']))
{
if ($login == $_POST['login'] && $password == $_POST['password']) {
function_alert("The authorization went well!");
} else {
function_alert("Something is incorrect...");
}
}
?>
<!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" />
<link href="styles.css" rel="stylesheet" />
<title>Project - ведение списков</title>
</head>
<body>
<div class="header">
<div class="logo"><img src="i/logo.png" width="68" height="23" alt="Project" /></div>
<div style="clear: both"></div>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="left-collum-index">
<h1>Возможности проекта —</h1>
<p>Вести свои личные списки, например покупки в магазине, цели, задачи и многое другое. Делится списками с друзьями и просматривать списки друзей.</p>
</td>
<td class="right-collum-index">
<div class="project-folders-menu">
<ul class="project-folders-v">
<li class="project-folders-v-active"><span><a href="">Авторизация</a></span></li>
<li><a href="#">Регистрация</a></li>
<li><a href="#">Забыли пароль?</a></li>
</ul>
<div style="clear: both;"></div>
</div>
<div class="index-auth">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form action="" method="post">
<tr>
<td class="iat">Ваш логин: <br/> <input type="text" size="30" name="login" /></td>
</tr>
<tr>
<td class="iat">Ваш пароль: <br/> <input type="password" size="30" name="password" /></td>
</tr>
<tr>
<td><input type="button" value="Войти" name="btn" /></td>
</tr>
</form>
</table>
</div>
</td>
</tr>
</table>
<div class="footer">© <nobr>2018</nobr> Project.</div>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Because script... appears earlier than !DOCTYPE html , you can use a boolean variable, and check it in head and output js alert, you can use a session with a header redirect, for example:
<?php
session_start();
function redirectBack($data = null) {
if (isset($data)) {
$_SESSION['answer'] = $data;
} else {
unset($_SESSION['answer']);
}
header('Location: '. $_SERVER['REQUEST_URI']); exit;
}
$login = 'Lane';
$password = 'admin';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (empty($_POST['login']) || empty($_POST['password'])) {
redirectBack("Something is incorrect...");
}
if ($_POST['login'] != $login || $_POST['password'] != $password) {
redirectBack("Something is incorrect...");
}
redirectBack("The authorization went well!");
}
?>
<!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" />
<link href="styles.css" rel="stylesheet" />
<title>Project - ведение списков</title>
</head>
<body>
<? if (!empty($_SESSION['answer'])) : ?>
<div class="alert alert-warning" role="alert">
<?= $_SESSION['answer']; ?>
</div>
<? endif; ?>
</body>
</html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question