The following files exists in this folder. Click to view.
add-words.php
api/
components/
include.php
index.php
ini/
login.php
logout.php
practice.php
progress.php
public/
scripts/
util/
word.php
add-words.php
57 lines ASCII Windows (CRLF)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
include "include.php";
login_guard();
if (isset($_POST["word"]) && isset($_POST["translations"])) {
$word = strtolower($_POST["word"]);
$translations = explode(";", $_POST["translations"]);
$userId = user_id();
try {
quick_statment("INSERT INTO word (word, user_id) VALUES (?, ?)", "si", $word, $userId);
} catch (Exception $e) {
// word already exists (just add new translation)
echo $e;
}
$wordId = quick_statment("SELECT id FROM word WHERE word=? AND user_id=?", "si", $word, $userId)->fetch_assoc()["id"];
// automatic translations
if ($_POST["auto"] == "on") {
$translations = get_predefined_translation($word);
}
foreach ($translations as $translation) {
quick_statment("INSERT INTO translation (translation, user_id, word_id) VALUES(?, ?, ?)", "sii", $translation, $userId, $wordId);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include "components/head.php" ?>
</head>
<body>
<?php include "components/header.php"; ?>
<main class="floating">
<form action="" method="post">
<p>Word</p>
<input name="word" type="text">
<div class="flex">
<p>Automatic translation</p>
<input type="checkbox" name="auto" id="" checked>
</div>
<p>Translations</p>
<textarea cols="50" name="translations" id=""></textarea>
<button>Submit</button>
</form>
</main>
</body>
</html>