Пишу что-то вроде блокнота, сохраняющего заметки в бд.
Вот страница входа
main.html
HTML5 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="/JustProject/Styles/main_style.css">
<title>Main Page</title>
</head>
<body>
<h3 class="text-center">Entering</h3>
<form action="enter.php" method="POST">
<div class="input-login">
<span style="margin-right: 0.5vw;">login: </span>
<input type="text" name="login">
</div>
<div class="input-password">
<span style="margin-right: 0.5vw;">password: </span>
<input type="text" name="password">
</div>
<div class="submit-buttons text-center">
<input type="submit" value="Enter" class="enter-button">
<a href="/JustProject/registration.html">Don`t have an acount?</a>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<script src="/JustProject/Scripts/main_script.js"></script>
</body>
</html> |
|
Вот скрипт срабатывающий при входе
enter.php
PHP |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| <?php
$conn = new mysqli('localhost', 'root', 'root', 'just_project_db');
$login = $_POST['login']; // login and password
$password = $_POST['password'];
$acount = $conn->query("SELECT * FROM `users` WHERE login='$login'"); // search acount
$result = $acount->fetch_assoc();
if ($result['login'] == NULL) { // if acount not real
readfile("WrongEnterLogin.html");
die();
}
if ($result['password'] != $password) { // if password wrong
readfile("WrongPassword.html");
die();
}
//readfile("NotePad.html");
require_once("NotePad.html");
$conn->close();
?> |
|
Далее открывается сам блокнот
NotePad.html
HTML5 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="Styles/main_style.css">
<title>NotePad</title>
</head>
<body>
<h3 class="text-center">NotePad</h3>
<h3 style="margin-left: 0.5vw;"><?php echo "Hello \"$login\""; ?></h3>
<div id="new-note" class="new-note">
<button id="plus-button">+</button>
<input style="margin-left: 0.5vw;" value="input name of note">
</div>
<form action="add_note.php" method="POST">
<div id="note-input" class="note-input">
<input class="text-note" type="text" name="note-value">
<div>
<button type="button" class="close-button" id="close-button">Close</button>
<input type="submit" value="Send">
</div>
</div>
</form>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<script src="Scripts/main_script.js"></script>
</body>
</html> |
|
И при нажатии кнопки "send" данный скрипт, должен отправлять заметку в таблицу
add_note.php
PHP |
1
2
3
| <?php
echo "add_note worked<br>";
?> |
|
Проблема заключается в том, что когда я добавляю строку в таблицу, в этой строке должен быть логин,
который пользователь ввёл на main.html. Мне непонятно, каким образом я могу получить этот логин.
Подскажите, пожалуйста.
Вернуться к обсуждению:
Перенести переменной из одного скрипта в другой PHP