简体   繁体   中英

Image not uploading into mysql database php

I am trying to upload an image by updating MySQL table column with the image location.

<?php
session_start();
if(isset($_POST['upload']))
{
$link = mysqli_connect("localhost", "root", "root", "rental");

if($link == false){ 
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
$image = $_FILES['propic']['tmp_name'];
$propic = addslashes(file_get_contents($image));
$lipic = "img/user.png";
$aadhar="img/user.png";
$sql= "UPDATE profiles SET profilepic='$propic', license='$lipic', aadhar='$aadhar' WHERE email='".$_SESSION['email']."'";
$result=mysqli_query($link,$sql);
}   
?>

HTML Code:

<form id="form" method="post" action="profile.php" enctype="multipart/form-data">
 <input type="file" name="propic" accept="image/*">
 <input type="file" name="lipic" accept="image/*">
 <input type="file" name="aapic" accept="image/*">
 <input type="submit" class="mybutton myfont" name="upload" value="Submit" style="width:100px; background-color:black;">
 </form>

MySQL table

在此处输入图片说明

Try this code. You are missing file uploading code.

$image = $_FILES['propic']['tmp_name'];
$name = "img/$_FILES['propic']['name']";
move_uploaded_file($image, $name); //Here you have to upload a file in a folder.

This is just for a reference. Use this and you will be able to upload a file on server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM