Hi, I'm a novice developer. First of all, I want to create applications that will be in demand.
In this project, I created a separate blog for my group.
It has such features as:
- adding homework;
- adding/downloading literature;
- adding photos to the album.
Also, for convenience, I created a chat bot in Telegram.
The project itself can be viewed on GitHub
How does file upload work?
Everything happens via POST requests. It's very simple! The user passes the photo through the form, then if the file has passed the check, it gets into the folder with all the photos. And a message about successful saving is displayed to the user.
$message = "";
ini_set('upload_max_filesize', '50M'); //ограничение в 50 мб
if ($_SERVER['REQUEST_METHOD'] == "POST" ) {
if ($_FILES['inputfile']['error'] == UPLOAD_ERR_OK && $_FILES['inputfile']['type'] == 'image/jpeg') { //проверка на наличие ошибок
$destiation_dir = '../library/' . $_FILES['inputfile']['name']; // директория для размещения файла
if (move_uploaded_file($_FILES['inputfile']['tmp_name'], $destiation_dir)) { //перемещение в желаемую директорию
$message = 'Файл загружен!';
} else {
$message = 'Ошибка.';
}
} else {
switch ($_FILES['inputfile']['error']) {
case UPLOAD_ERR_FORM_SIZE:
case UPLOAD_ERR_INI_SIZE:
$message = 'Фаил не должен привышать 50 мегабайт.';
brake;
case UPLOAD_ERR_NO_FILE:
$message = 'Файл не выбран';
break;
}
}
}
How does adding homework work?
Homework is added almost identically to adding files. But SQL queries are used here.
require_once('../public_html/databaseconnect.php');
$conn = mysqli_connect($servername, $username, $password, $database);
$conn->query("SET NAMES UTF8");
$conn->query("SET CHARACTER SET UTF8");
$conn->query("SET character_set_client = UTF8");
$conn->query("SET character_set_connection = UTF8");
$conn->query("SET character_set_results = UTF8");
$errors = "";
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if (strtotime($_POST['dateTime']) > strtotime(date("Y-m-d")))
{
$group = $_POST['group_select'];
$disticiline = $_POST['discipline_select'];
$dateTime = $_POST['dateTime'];
$text = $_POST['text'];
$query = "INSERT INTO `home_work`(`id_discipline`, `id_group`, `text`, `date`) VALUES ('$disticiline','$group','$text','$dateTime')";
$rez = mysqli_query($conn, $query);
if ($rez > 0)
{
header( 'Location: /pages/homework.php');
}
else
{
$errors = "Ошибка запроса.";
}
$conn->close();
}
else $errors = "Неверный формат даты.";
}
What kind of Statement?
The statement is a complete list with all subjects and grades of students. Each student fills in their own results in the form. You can also track changes in the chatbot.
In fact, many people did not use the statement, but it was interesting for me to implement it.
if ($_POST['id_group']) {
$query = "SELECT * FROM `users` WHERE `id_group` = ".$_POST['id_group'];
$result = $conn->query($query);
if ($result->num_rows > 0)
{
echo '<option>Студент</option>';
while ($row = $result->fetch_assoc())
{
echo '<option value="'.$row['id'].'">'.$row['FirstName'].' '.$row['MidleName'].'</option>';
}
}
else
{
echo '<option>Нет данных</option>';
}
}
elseif ($_POST['id_student'])
{
$query = "SELECT discipline.name, SUM(count_v), value FROM `statement` INNER JOIN users ON statement.id = users.id INNER JOIN discipline ON statement.id_discipline = discipline.id WHERE statement.id_user = ".$_POST['id_student'] . " GROUP BY name";
$result = $conn->query($query);
$arr = array();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$arr[] = $row['value'];
echo '<tr><th scope="row">' . $row['name'] . '</th>' . '<td>' . $row['SUM(count_v)'] . '</td>' . '<td>' . $row['value'] . "</td></tr>";
}
}
else
{
echo '<td></td>';
}
}
What have I learned?
Ajax requests! This is very convenient.
function FetchGroup(id) {
$('#student').html('Студент');
$.ajax({
type:'post',
url:'../ajax/ajaxdata.php',
data: {
id_group: id
},
success: function (data) {
$('#student').html(data);
}
})
}
function FetchStudent(id) {
$('#statement').html('Студент');
$('#statement_2').html('');
$.ajax({
type:'post',
url:'../ajax/ajaxdata.php',
data: {
id_student: id
},
success: function (data) {
$('#statement').html(data);
$('#statement_2').html(data);
}
})
}
P.S. So far, my skills with JS are very small, but I will continue to level up.
Thank you for reading this post. I will be glad of any criticism! :)
Top comments (2)
Poor post, add some codes examples from your GitHub repository to a better post ! 🥳
Thanks for the feedback, I'm just studying this social network. I will be glad if you write that you can add more :)