The write code in the database works, but there is no loading of the file (image).

Here is the code:

<?php $result = $mysqli->query('SELECT MAX(id) FROM pulpit'); $row = $result->fetch_row(); $highest_id = $row[0]; ?> <div class="row"> <div class="col-lg-6 text-center"> <form enctype="multipart/form-data" action="admin" method="post"> <div class="form-group row"> <label for="id" class="col-2 col-form-label text-left">ID</label> <div class="col-10"> <input name="id" class="form-control" type="text" value="<?php echo $highest_id + 1 ?>" id="id"> </div> </div> <div class="form-group row"> <label for="title" class="col-2 col-form-label text-left">Назва кафедри</label> <div class="col-10"> <input name="title" class="form-control" type="text" placeholder="Назва кафедри..." id="title"> </div> </div> <div class="form-group row"> <label for="head_fullname" class="col-2 col-form-label text-left">ПІБ зама кафедри</label> <div class="col-10"> <input name="head_fullname" class="form-control" type="text" placeholder="ПІБ..." id="head_fullname"> </div> </div> <div class="form-group row"> <label for="venue" class="col-2 col-form-label text-left">Місце знаходження</label> <div class="col-10"> <input name="venue" class="form-control" type="text" placeholder="Місце знаходження..." id="venue"> </div> </div> <div class="form-group row"> <label for="phone" class="col-2 col-form-label text-left">Телефон</label> <div class="col-10"> <input name="phone" class="form-control" type="text" placeholder="Номер телефону(7 цифр).." id="phone"> </div> </div> <div class="form-group"> <label for="description">Опис</label> <textarea name="history" class="form-control" id="description" rows="3"></textarea> </div> <div class="form-group"> <label for="history">Історія</label> <textarea name="history" class="form-control" id="history" rows="3"></textarea> </div> <div class="form-group"> <label for="InputFile">Фото зав. кафедри</label> <input type="file" class="form-control-file" id="InputFile" aria-describedby="fileHelp"> <small id="fileHelp" class="form-text text-muted">Текст довідка</small> </div> <div class="form-group"> <button type="submitPulpit" id="submitPulpit" name="submitPulpit" class="btn pull-right">Додати запис</button> </div> </form> </div> </div> <?php if(isset($_POST['submitPulpit'])) { $id = $_POST['id']; $title = $_POST['title']; $head_photo = $_FILES['InputFile']['name']; $head_fullname = $_POST['head_fullname']; $description = $_POST['description']; $venue = $_POST['venue']; $phone = $_POST['phone']; $history = $_POST['history']; $count_teacher = 0; $count_teacher = 0; $new_file = '/uploadfiles/pulpit/'.$_FILES['InputFile']['name']; if (copy($_FILES['InputFile']['tmp_name'], $new_file)) { $sql = "INSERT INTO pulpit (`id`, `title`, `head_photo`, `head_fullname`, `description`, `venue`, `phone` ,`history`, `count_teacher`, `count_discipline`) VALUES ('$id','$title','$head_photo','$head_fullname','$description','$venue','$phone','$history','$count_teacher','$count_teacher')"; $result = $mysqli->query($sql); if ($result==true) { echo "<br>Информация в базу добавлена успешно."; header("Location: admin"); } else echo $mysqli->error(); } else echo "Ошибка при загрузке файла"; } ?> 
  • You can try to connect via FTP - AtCliff_

3 answers 3

Corrected code, there were minor errors and errors in the name of the folder where to save, I think you will notice the difference yourself:

 <?php $result = $mysqli->query('SELECT MAX(id) FROM pulpit'); $row = $result->fetch_row(); $highest_id = $row[0]; ?> <div class="row"> <div class="col-lg-6 text-center"> <form enctype="multipart/form-data" action="" method="post"> <div class="form-group row"> <label for="id" class="col-2 col-form-label text-left">ID</label> <div class="col-10"> <input name="id" class="form-control" type="text" value="<?php echo $highest_id + 1 ?>" id="id"> </div> </div> <div class="form-group row"> <label for="title" class="col-2 col-form-label text-left">Назва кафедри</label> <div class="col-10"> <input name="title" class="form-control" type="text" placeholder="Назва кафедри..." id="title"> </div> </div> <div class="form-group row"> <label for="head_fullname" class="col-2 col-form-label text-left">ПІБ зама кафедри</label> <div class="col-10"> <input name="head_fullname" class="form-control" type="text" placeholder="ПІБ..." id="head_fullname"> </div> </div> <div class="form-group row"> <label for="venue" class="col-2 col-form-label text-left">Місце знаходження</label> <div class="col-10"> <input name="venue" class="form-control" type="text" placeholder="Місце знаходження..." id="venue"> </div> </div> <div class="form-group row"> <label for="phone" class="col-2 col-form-label text-left">Телефон</label> <div class="col-10"> <input name="phone" class="form-control" type="text" placeholder="Номер телефону(7 цифр).." id="phone"> </div> </div> <div class="form-group"> <label for="description">Опис</label> <textarea name="description" class="form-control" id="description" rows="3"></textarea> </div> <div class="form-group"> <label for="history">Історія</label> <textarea name="history" class="form-control" id="history" rows="3"></textarea> </div> <div class="form-group"> <label for="InputFile">Фото зав. кафедри</label> <input type="file" class="form-control-file" id="InputFile" name="InputFile" aria-describedby="fileHelp"> <small id="fileHelp" class="form-text text-muted">Текст довідка</small> </div> <div class="form-group"> <button type="submitPulpit" id="submitPulpit" name="submitPulpit" class="btn pull-right">Додати запис</button> </div> </form> </div> </div> <?php if(isset($_POST['submitPulpit'])) { $id = $_POST['id']; $title = $_POST['title']; $head_photo = $_FILES['InputFile']['name']; $head_fullname = $_POST['head_fullname']; $description = $_POST['description']; $venue = $_POST['venue']; $phone = $_POST['phone']; $history = $_POST['history']; $count_teacher = 0; $new_file = './uploadfiles/pulpit/'.basename($_FILES['InputFile']['name']); if (copy($_FILES['InputFile']['tmp_name'], $new_file)) { $sql = "INSERT INTO pulpit (`id`, `title`, `head_photo`, `head_fullname`, `description`, `venue`, `phone` ,`history`, `count_teacher`, `count_discipline`) VALUES ('$id','$title','$head_photo','$head_fullname','$description','$venue','$phone','$history','$count_teacher','$count_teacher')"; $result = $mysqli->query($sql); if ($result==true) { echo "<br>Информация в базу добавлена успешно."; header("Location: admin"); } else echo $mysqli->error(); } else echo "Ошибка при загрузке файла"; } ?> 

    Perhaps it is worth checking the path where you write

    1. Make it not relative, but absolute $ new_file = DIR . '/ Uploadfiles / pulpit /'.$_ FILES [' InputFile '] [' name '];
    2. Check the rights to write to the folder

    Add the name attribute to the input , without it you will not find the file