I'm developing a back end for my blog, the code to upload images is working as expected but in database nothing is writing. When i submit it uploads the image and moves it to the designated folder but in the database there is no record inserted. Here is the php for uploading. Is there any way to solve this issue?
<form method="POST" action="functionabout.php" enctype="multipart/form-data">
<div class="col-md-9">
<!-- general form elements -->
<div class="box box-primary"> <div class="box-header with-border">
<h3 class="box-title">Add About Content</h3>
</div>
<!-- /.box-body -->
<div class="box-body">
<div class="form-group">
<label for="heading">Heading</label>
<input placeholder="Write Heading" class="form-control" name="heading" type="text" id="heading" required>
</div>
<div class="form-group">
<label for="subheading">Sub Heading</label>
<textarea class="form-control" placeholder="Write Sub Heading" name="subheading" cols="50" rows="10" id="subheading" required></textarea>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea placeholder="Write Details" class="form-control" name="message" cols="50" rows="10" id="message" required></textarea>
</div>
<div class="form-group">
<label for="Filename">Signature</label>
<input name="Filename" type="file">
</div>
</div>
<div class="box-footer fboxm">
<button type="submit" class="btn btn-primary"><i class="fa fa-check icheck"></i>Submit</button>
<button type="reset" class="btn btn-warning"><i class="fa fa-undo icheck"></i>Reset</button>
</div>
</div>
</div>
</div>
<!-- /.box -->
</div>
<!-- right column -->
</form>
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['Filename']['name']);
//This gets all the other information from the form
$Filename=basename( $_FILES['Filename']['name']);
$heading=$_POST['heading'];
$subheading=$_POST['subheading'];
$message=$_POST['message'];
//Writes the Filename to the server
if(move_uploaded_file($_FILES['Filename']['tmp_name'], $target)) {
//Tells you if its all ok
echo "The file ". basename( $_FILES['Filename']['name']). " has been uploaded, and your information has been added to the directory";
// Connects to your Database
$conn = mysqli_connect('localhost', 'root', '', 'db');
//Writes the information to the database
mysqli_query($conn,"INSERT INTO about (subheading,heading,message,signature)
VALUES ('$subheading',$heading','$message','$Filename')") ;
} else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
id int(11) PK
subheading varchar(255)
heading varchar(255)
message varchar(255)
signature varchar(255)
I expect to upload both the file and update the database too.