Загрузка переменной в базу данных
Я загружаю картинку на сервер. Но как я могу поместить ее еще и в базу данных? INSERT, что я использую ниже не срабатывает. То есть, запись не происходит. В чем может быть ошибка?
<?php
if(isset($_POST['save'])){
$conn = mysqli_connect("localhost", "root", "", "my-db2");
$path="/var/www/myshop33.ru/bootstrap/users_images/";
$name = $_FILES['imageupload']['name'];//Name of the File
$temp = $_FILES['imageupload']['tmp_name'];
if(move_uploaded_file($temp, $path . $name)){
echo "success";
$query = "INSERT INTO customers(userfile) VALUES ('" . $name . "')";
$result = mysqli_query($conn, $query);
}else{
echo "failed";
}
}
?>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="imageupload">
<input type="submit" name="save" value="submit">
</form>
<form method="post" action="profile.php" class="form-row">
<div class="col-md-3 text-center">
<img class="img-responsive img-thumbnail " src="./bootstrap/users_images/<?php echo $name; ?>">
</div>
</form>
UPD:
<?php
if(isset($_POST['save'])){
require_once "./functions/database_functions.php";
require "./template/header.php";
$conn = db_connect();
$path="/var/www/myshop33.ru/bootstrap/users_images/";
$userfile = $_FILES['imageupload']['name'];//Name of the File
$temp = $_FILES['imageupload']['tmp_name'];
if(move_uploaded_file($temp, $path . $userfile)){
echo "success";
require_once("./functions/database_functions.php");
$customer = getCustomerIdbyEmail($_SESSION['email']);
$id=$customer['id'];
$query="UPDATE customers set
userfile='$userfile' where id='$id'";
mysqli_query($conn, $query);
}
}
?>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="imageupload">
<input type="submit" name="save" value="submit">
</form>
<form method="post" action="profile.php" class="form-row">
<div class="col-md-3 text-center">
<img class="img-responsive img-thumbnail " src="./bootstrap/users_images/<?php echo $userfile; ?>">
</div>
</form>
UPD 2: download_img.php
<?php
ini_set('display_errors',1);
error_reporting(E_ALL ^E_NOTICE);
error_reporting(E_ALL);
if(isset($_POST['save'])){
require_once "./functions/database_functions.php";
require "./template/header.php";
$conn = db_connect();
$path="/var/www/myshop33.ru/bootstrap/users_images/";
$userfile = $_FILES['imageupload']['name'];//Name of the File
$temp = $_FILES['imageupload']['tmp_name'];
if(move_uploaded_file($temp, $path . $userfile)){
header("Location: profile.php");
require_once("./functions/database_functions.php");
$customer = getCustomerIdbyEmail($_SESSION['email']);
$id=$customer['id'];
$query="UPDATE customers set
userfile='$userfile' where id='$id'";
mysqli_query($conn, $query);
}
}
?>
UPD 2: profile.php
<?php
session_start();
require_once "./functions/database_functions.php";
$title = "Profile";
require "./template/header.php";
// connect database
if(isset($_SESSION['email'])){
$customer = getCustomerIdbyEmail($_SESSION['email']);
?>
<form method="post" action="download_img.php" enctype="multipart/form-data">
<input type="file" name="imageupload">
<input type="submit" name="save" value="submit">
<input type="submit" name="delete" value="delete">
</form>
<form method="post" action="profile.php" class="form-row">
<div class="col-md-3 text-center">
<img class="img-responsive img-thumbnail " src="./bootstrap/users_images/<?php echo $customer['userfile']; ?>">
</div>
</form>