I created a form where using PHP and MySQL .Here people can input text and upload image.My image upload part is working .Image is storing in database but text does no store in database
My codes are below :
index.php
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="text" name="username">
<input type="text" name="report">
Select image to upload:
<input type="file" name="image"/>
<input type="submit" name="submit" value="UPLOAD"/>
</form>
upload.php
<?php
if(isset($_POST["submit"])){
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false){
$image = $_FILES['image']['tmp_name'];
$imgContent = addslashes(file_get_contents($image));
/*
* Insert image data into database
*/
//DB details
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPassword = 'root';
$dbName = 'testreport';
//Create connection and select DB
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
// Check connection
if($db->connect_error){
die("Connection failed: " . $db->connect_error);
}
$username = mysqli_real_escape_string($link, $_REQUEST['username']);
$report = mysqli_real_escape_string($link, $_REQUEST['report']);
$dataTime = date("Y-m-d H:i:s");
//Insert image content into database
$insert = $db->query("INSERT into images (username,report,image, created) VALUES ('$username','$report','$imgContent', '$dataTime')");
if($insert){
echo "File uploaded successfully.";
}else{
echo "File upload failed, please try again.";
}
}else{
echo "Please select an image file to upload.";
}
}
?>