Click here to Skip to main content
15,900,322 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<?php
$msg = "";

if (isset($_POST['upload'])){

$target = "images/".basename($_FILES['image']['name']);


$db = mysqli_connect("localhost", "root", "", "photos");

$image = $_FILES['image']['name'];

$text = $_POST['text'];

$sql = "INSERT INTO images (image, text) VALUES ('$image', '$text')";
mysqli_query($db, $sql);

// Now let's move the uploaded image into the folder: images
if (move_uploaded_file($_FILES['image']['tmp_name'], $target)){
$msg = "image upload successfully";



}else{
$msg = "There was a problem uploading image";
}

}

?>

What I have tried:

Notice: Undefined index: image in C:\xampp\htdocs\projects\upload_image\index.php on line 7

Notice: Undefined index: image in C:\xampp\htdocs\projects\upload_image\index.php on line 12

Notice: Undefined index: image in C:\xampp\htdocs\projects\upload_image\index.php on line 20
Posted
Updated 13-Sep-18 6:35am

You have ask three questions:
1. How to upload image: PHP 5 File Upload[^]
2. How to insert image in mysql database: Uploading files into a MySQL database using PHP - PHP[^]
3. How to retrieve image and attach with php: answer 2 will tell you how to handle this

And finally:
* PHP Insert files in mysql database - Stack Overflow[^]
Read the answer. It will give you a better suggestion
 
Share this answer
 
add enctype="multipart/form-data"
on your form tag
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900