I am trying to do that if the user only adds 2-3 images still it could send the image and image name to the Database. I tried and created ($sql4) for it but it shows an error that the file type is not supported, and I also checked that the file type it was the (png file). Please help me.
add_blog.php
<?php include 'header.php';
if (isset($_SESSION['user_data'])) {
// This will fetch the author id that is stored in index['0'].
$author_id = $_SESSION['user_data']['0'];
$sql = "SELECT * FROM categories";
$query = mysqli_query($config, $sql);
}
?>
<div class="container">
<h5 class="mb-2 text-gray-800">School</h5>
<div class="row">
<div class="col-xl-8 col-lg-6">
<div class="card">
<div class="card-header">
<h6 class="font-weight-bold text-primary mt-2">Add School</h6>
</div>
<div class="card-body">
<form action="" method="POST" enctype="multipart/form-data">
<div class="mb-3">
<input type="text" name="blog_title" placeholder="Title" class="form-control">
</div>
<div class="mb-3">
<input type="text" name="school_tagline" placeholder="Tagline" class="form-control">
</div>
<div class="mb-3">
<input type="text" name="school_rating" placeholder="Rating" class="form-control">
</div>
<div class="mb-3">
<input type="text" name="school_projects" placeholder="Projects" class="form-control">
</div>
<div class="mb-3">
<input type="text" name="school_events" placeholder="School Events" class="form-control">
</div>
<div class="mb-3">
<input type="number" name="school_mobile" placeholder="School Number" class="form-control">
</div>
<div class="mb-3">
<input type="text" name="school_email" placeholder="School Email" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_facility" placeholder="Facilities your school have" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_2.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_facility_2" placeholder="Facilities 2" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_3.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_facility_3" placeholder="Facilities 3" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_4.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_facility_4" placeholder="Facilities 4" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_5.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_facility_5" placeholder="Facilities 5" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_6.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_facility_6" placeholder="Facilities 6" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_7.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_facility_7" placeholder="Facilities 7" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_8.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_facility_8" placeholder="Facilities 8" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_activities.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_activities_heading_1" placeholder="School Activities Heading" class="form-control">
</div>
<div class="mb-3">
<input type="text" name="school_activities_para_1" placeholder="School activities Paragraph" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_activities_2.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_activities_heading_2" placeholder="School activities Heading 2" class="form-control">
</div>
<div class="mb-3">
<input type="text" name="school_activities_para_2" placeholder="School Activities Paragraph 2" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_activities_3.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_activities_heading_3" placeholder="School activities Heading 3" class="form-control">
</div>
<div class="mb-3">
<input type="text" name="school_activities_para_3" placeholder="School activities Paragraph 3" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_mission.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_mission_heading" placeholder="School Mission Heading" class="form-control">
</div>
<div class="mb-3">
<input type="text" name="school_mission_para" placeholder="School Mission Paragraph" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_vision.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_vision_heading" placeholder="School Vision Heading" class="form-control">
</div>
<div class="mb-3">
<input type="text" name="school_vision_para" placeholder="School Vision Paragraph" class="form-control">
</div>
<div class="mb-3">
<label for="">About School Infomartion</label>
<textarea class="form-control" name="blog_body" id="blog" rows="2"></textarea>
</div>
<div class="mb-3">
<label for="">School Activities Infomartion</label>
<textarea class="form-control" name="school_activities" id="blog_1" rows="2"></textarea>
</div>
<div class="mb-3">
<label for="">If you have mission or vision please describe</label>
<textarea class="form-control" name="school_mission_vision" id="blog_2" rows="2"></textarea>
</div>
<div class="mb-3">
<input type="file" name="blog_image" class="form-control">
</div>
<div class="mb-3">
<input type="file" name="school_image" class="form-control">
</div>
<div class="mb-3">
<input type="file" name="school_image_2" class="form-control">
</div>
<div class="mb-3">
<input type="file" name="school_image_3" class="form-control">
</div>
<div class="mb-3">
<input type="file" name="school_image_4" class="form-control">
</div>
<div class="mb-3">
<input type="file" name="school_image_5" class="form-control">
</div>
<div class="mb-3">
<input type="file" name="school_image_6" class="form-control">
</div>
<div class="mb-3">
<input type="file" name="school_image_7" class="form-control">
</div>
<div class="mb-3">
<input type="file" name="school_image_8" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_social.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_instagram" placeholder="Instagram Link" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_social_2.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_facebook" placeholder="Facebook Link" class="form-control">
</div>
<div class="mb-3">
<?php include 'icons_social_3.php'; ?>
</div>
<div class="mb-3">
<input type="text" name="school_twitter" placeholder="Twitter Link" class="form-control">
</div>
<div class="mb-3">
<select class="form-control" name="category">
<option value="" name="category">Select Category</option>
<!-- $cats will fetch all all the data that is store in the categories. -->
<?php while ($cats = mysqli_fetch_assoc($query)) { ?>
<option value="<?= $cats['cat_id'] ?>">
<?= $cats['cat_name'] ?>
</option>
<?php } ?>
}
</select>
</div>
<div class="mb-3">
<input type="submit" name="add_blog" value="Add" class="btn btn-primary">
<a class="btn btn-secondary" href="index.php">Back</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
include 'footer.php';
// If the user click on Add button then the user data should upload to the database.
if (isset($_POST['add_blog'])) {
$title = mysqli_real_escape_string($config, $_POST['blog_title']);
$tagline = mysqli_real_escape_string($config, $_POST['school_tagline']);
$rating = mysqli_real_escape_string($config, $_POST['school_rating']);
$projects = mysqli_real_escape_string($config, $_POST['school_projects']);
$events = mysqli_real_escape_string($config, $_POST['school_events']);
$mobile = mysqli_real_escape_string($config, $_POST['school_mobile']);
$email = mysqli_real_escape_string($config, $_POST['school_email']);
$activities = mysqli_real_escape_string($config, $_POST['school_activities']);
$missionVision = mysqli_real_escape_string($config, $_POST['school_mission_vision']);
$body = mysqli_real_escape_string($config, $_POST['blog_body']);
$icon = mysqli_real_escape_string($config, $_POST['icon_input']);
$facility_1 = mysqli_real_escape_string($config, $_POST['school_facility']);
$icon2 = mysqli_real_escape_string($config, $_POST['icon_input_2']);
$facility_2 = mysqli_real_escape_string($config, $_POST['school_facility_2']);
$icon3 = mysqli_real_escape_string($config, $_POST['icon_input_3']);
$facility_3 = mysqli_real_escape_string($config, $_POST['school_facility_3']);
$icon4 = mysqli_real_escape_string($config, $_POST['icon_input_4']);
$facility_4 = mysqli_real_escape_string($config, $_POST['school_facility_4']);
$icon5 = mysqli_real_escape_string($config, $_POST['icon_input_5']);
$facility_5 = mysqli_real_escape_string($config, $_POST['school_facility_5']);
$icon6 = mysqli_real_escape_string($config, $_POST['icon_input_6']);
$facility_6 = mysqli_real_escape_string($config, $_POST['school_facility_6']);
$icon7 = mysqli_real_escape_string($config, $_POST['icon_input_7']);
$facility_7 = mysqli_real_escape_string($config, $_POST['school_facility_7']);
$icon8 = mysqli_real_escape_string($config, $_POST['icon_input_8']);
$facility_8 = mysqli_real_escape_string($config, $_POST['school_facility_8']);
$icon_mission = mysqli_real_escape_string($config, $_POST['icons_mission']);
$mission_heading = mysqli_real_escape_string($config, $_POST['school_mission_heading']);
$mission_para = mysqli_real_escape_string($config, $_POST['school_mission_para']);
$icon_vision = mysqli_real_escape_string($config, $_POST['icons_vision']);
$vision_heading = mysqli_real_escape_string($config, $_POST['school_vision_heading']);
$vision_para = mysqli_real_escape_string($config, $_POST['school_vision_para']);
$icon_activities = mysqli_real_escape_string($config, $_POST['icons_activities']);
$activities_heading_1 = mysqli_real_escape_string($config, $_POST['school_activities_heading_1'])
;
$activities_para_1 = mysqli_real_escape_string($config, $_POST['school_activities_para_1']);
$icon_activities_2 = mysqli_real_escape_string($config, $_POST['icons_activities_2']);
$activities_heading_2 = mysqli_real_escape_string($config, $_POST['school_activities_heading_2']);
$activities_para_2 = mysqli_real_escape_string($config, $_POST['school_activities_para_2']);
$icon_activities_3 = mysqli_real_escape_string($config, $_POST['icons_activities_3']);
$activities_heading_3 = mysqli_real_escape_string($config, $_POST['school_activities_heading_3']);
$activities_para_3 = mysqli_real_escape_string($config, $_POST['school_activities_para_3']);
$filename = $_FILES['blog_image']['name'];
$tmp_name = $_FILES['blog_image']['tmp_name'];
$size = $_FILES['blog_image']['size'];
$filename1 = $_FILES['school_image']['name'];
$tmp_name1 = $_FILES['school_image']['tmp_name'];
$size1 = $_FILES['school_image']['size'];
$filename2 = $_FILES['school_image_2']['name'];
$tmp_name2 = $_FILES['school_image_2']['tmp_name'];
$size2 = $_FILES['school_image_2']['size'];
$filename3 = $_FILES['school_image_3']['name'];
$tmp_name3 = $_FILES['school_image_3']['tmp_name'];
$size3 = $_FILES['school_image_3']['size'];
$filename4 = $_FILES['school_image_4']['name'];
$tmp_name4 = $_FILES['school_image_4']['tmp_name'];
$size4 = $_FILES['school_image_4']['size'];
$filename5 = $_FILES['school_image_5']['name'];
$tmp_name5 = $_FILES['school_image_5']['tmp_name'];
$size5 = $_FILES['school_image_5']['size'];
$filename6 = $_FILES['school_image_6']['name'];
$tmp_name6 = $_FILES['school_image_6']['tmp_name'];
$size6 = $_FILES['school_image_6']['size'];
$filename7 = $_FILES['school_image_7']['name'];
$tmp_name7 = $_FILES['school_image_7']['tmp_name'];
$size7 = $_FILES['school_image_7']['size'];
$filename8 = $_FILES['school_image_8']['name'];
$tmp_name8 = $_FILES['school_image_8']['tmp_name'];
$size8 = $_FILES['school_image_8']['size'];
$social_icon = mysqli_real_escape_string($config, $_POST['icon_social']);
// This will make the connect to database and will post the data to the database.
$instagram = mysqli_real_escape_string($config, $_POST['school_instagram']);
// $filename variable will have the image and image name. $_FILES will upload the image to the database.
$social_icon_2 = mysqli_real_escape_string($config, $_POST['icon_social_2']);
// This will make the connect to database and will post the data to the database.
$facebook = mysqli_real_escape_string($config, $_POST['school_facebook']);
// $filename variable will have the image and image name. $_FILES will upload the image to the database.
$social_icon_3 = mysqli_real_escape_string($config, $_POST['icon_social_3']);
// This will make the connect to database and will post the data to the database.
$twitter = mysqli_real_escape_string($config, $_POST['school_twitter']);
// $image_ext variable will lower the extionsion letter for example if the extension is (PNG) it will be convert to lower case (png). So this variable will get the file name and the extension of the file.
$image_ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$image_ext1 = strtolower(pathinfo($filename1, PATHINFO_EXTENSION));
$image_ext2 = strtolower(pathinfo($filename2, PATHINFO_EXTENSION));
$image_ext3 = strtolower(pathinfo($filename3, PATHINFO_EXTENSION));
$image_ext4 = strtolower(pathinfo($filename4, PATHINFO_EXTENSION));
$image_ext5 = strtolower(pathinfo($filename5, PATHINFO_EXTENSION));
$image_ext6 = strtolower(pathinfo($filename6, PATHINFO_EXTENSION));
$image_ext7 = strtolower(pathinfo($filename7, PATHINFO_EXTENSION));
$image_ext8 = strtolower(pathinfo($filename8, PATHINFO_EXTENSION));
// $allow_type varibale have the set the extension file type that are supported.
$allow_type = ['jpg', 'png', 'jpeg', 'webp', 'svg'];
// $destination varibale is set to upload the image to the given path folder "upload/". So it will send the particurlar file that is selected by the user.
$destination = "upload/" . $filename;
$destination1 = "upload/" . $filename1;
$destination2 = "upload/" . $filename2;
$destination3 = "upload/" . $filename3;
$destination4 = "upload/" . $filename4;
$destination5 = "upload/" . $filename5;
$destination6 = "upload/" . $filename6;
$destination7 = "upload/" . $filename7;
$destination8 = "upload/" . $filename8;
// This will make the connect to database and will post the data to the database.
$category = mysqli_real_escape_string($config, $_POST['category']);
if (!empty($filename)) {
if (!empty($filename1)) {
// In this (if statement) there is function called in_array that will ckeck the value in array that it exists or not. If the file extension matches then upload the file else show the error.
if (in_array($image_ext, $allow_type) && in_array($image_ext1, $allow_type) && in_array($image_ext2, $allow_type) && in_array($image_ext3, $allow_type) && in_array($image_ext4, $allow_type) && in_array($image_ext5, $allow_type) && in_array($image_ext6, $allow_type) && in_array($image_ext7, $allow_type) && in_array($image_ext8, $allow_type)) {
// If the file size is lesser then 5MB then upload the file else show error.
if ($size <= 5000000) {
// If the image validation checks pass then move it to this folder
move_uploaded_file($tmp_name, $destination);
move_uploaded_file($tmp_name1, $destination1);
move_uploaded_file($tmp_name2, $destination2);
move_uploaded_file($tmp_name3, $destination3);
move_uploaded_file($tmp_name4, $destination4);
move_uploaded_file($tmp_name5, $destination5);
move_uploaded_file($tmp_name6, $destination6);
move_uploaded_file($tmp_name7, $destination7);
move_uploaded_file($tmp_name8, $destination8);
// This wll insert all the input that is field by the user in the database blog section.
$sql2 = "INSERT INTO blog(blog_title, school_tagline, school_rating, school_projects, school_events, school_mobile, school_email, blog_body, icon_input, school_facility, icon_input_2, school_facility_2, icon_input_3, school_facility_3, icon_input_4, school_facility_4, icon_input_5, school_facility_5, icon_input_6, school_facility_6, icon_input_7, school_facility_7, icon_input_8, school_facility_8, icons_activities, school_activities_heading_1, school_activities_para_1, icons_activities_2, school_activities_heading_2, school_activities_para_2, icons_activities_3, school_activities_heading_3, school_activities_para_3, icons_mission, school_mission_heading, school_mission_para, icons_vision, school_vision_heading, school_vision_para, school_activities, school_mission_vision, blog_image, school_images, school_images_2, school_images_3, school_images_4, school_images_5, school_images_6, school_images_7, school_images_8, icon_social, school_instagram, icon_social_2, school_facebook, icon_social_3, school_twitter, category, author_id) VALUES('$title', '$tagline', '$rating', '$projects', '$events', '$mobile', '$email', '$body', '$icon', '$facility_1', '$icon2', '$facility_2', '$icon3', '$facility_3', '$icon4', '$facility_4', '$icon5', '$facility_5', '$icon6', '$facility_6', '$icon7', '$facility_7', '$icon8', '$facility_8', '$icon_activities', '$activities_heading_1', '$activities_para_1', '$icon_activities_2', '$activities_heading_2', '$activities_para_2', '$icon_activities_3', '$activities_heading_3', '$activities_para_3', '$icon_mission', '$mission_heading', '$mission_para', '$icon_vision', '$vision_heading', '$vision_para', '$activities', '$missionVision', '$filename', '$filename1', '$filename2', '$filename3', '$filename4', '$filename5', '$filename6', '$filename7', '$filename8', '$social_icon', '$social_icon_2', '$social_icon_3', '$instagram', '$facebook', '$twitter', '$category', '$author_id')";
$query2 = mysqli_query($config, $sql2);
if ($query2) {
$msg = ["Post Publish Successfully", "alert-success"];
$_SESSION['msg'] = $msg;
// If the post publish successfully then redirect to same page with success message.
header("location:add_blog.php");
} else {
$msg = ["Failed, Please try again", "alert-danger"];
$_SESSION['msg'] = $msg;
// If the post it not able to post then redirect to same page with error message.
header("location:add_blog.php");
}
} else {
$msg = ["Image file size should not be greater then 5MB", "alert-danger"];
$_SESSION['msg'] = $msg;
// If the file size is bigger then 5MB then redirect to same page with error message.
header("location:add_blog.php");
}
} else {
$msg = ["Image file type is not allowed (only jpg, jpeg, png, webp, svg)", "alert-danger"];
$_SESSION['msg'] = $msg;
// If the file extension is not supported then redirect to same page with error message.
header("location:add_blog.php");
}
} else {
$sql3 = "INSERT INTO blog(blog_title, school_tagline, school_rating, school_projects, school_events, school_mobile, school_email, blog_body, icon_input, school_facility, icon_input_2, school_facility_2, icon_input_3, school_facility_3, icon_input_4, school_facility_4, icon_input_5, school_facility_5, icon_input_6, school_facility_6, icon_input_7, school_facility_7, icon_input_8, school_facility_8, icons_activities, school_activities_heading_1, school_activities_para_1, icons_activities_2, school_activities_heading_2, school_activities_para_2, icons_activities_3, school_activities_heading_3, school_activities_para_3, icons_mission, school_mission_heading, school_mission_para, icons_vision, school_vision_heading, school_vision_para, school_activities, school_mission_vision, icon_social, school_instagram, icon_social_2, school_facebook, icon_social_3, school_twitter, category, author_id) VALUES('$title', '$tagline', '$rating', '$projects', '$events', '$mobile', '$email', '$body', '$icon', '$facility_1', '$icon2', '$facility_2', '$icon3', '$facility_3', '$icon4', '$facility_4', '$icon5', '$facility_5', '$icon6', '$facility_6', '$icon7', '$facility_7', '$icon8', '$facility_8', '$icon_activities', '$activities_heading_1', '$activities_para_1', '$icon_activities_2', '$activities_heading_2', '$activities_para_2', '$icon_activities_3', '$activities_heading_3', '$activities_para_3', '$icon_mission', '$mission_heading', '$mission_para', '$icon_vision', '$vision_heading', '$vision_para', '$activities', '$missionVision', '$social_icon', '$social_icon_2', '$social_icon_3', '$instagram', '$facebook', '$twitter', '$category', '$author_id')";
$query3 = mysqli_query($config, $sql3);
if ($query3) {
$msg = ["Post Publish Successfully", "alert-success"];
$_SESSION['msg'] = $msg;
// If the post publish successfully then redirect to same page with success message.
header("location:add_blog.php");
} else {
$msg = ["Failed, Please try again", "alert-danger"];
$_SESSION['msg'] = $msg;
// If the post it not able to post then redirect to same page with error message.
header("location:add_blog.php");
}
}
} else{
$sql4 = "INSERT INTO blog(blog_title, school_tagline, school_rating, school_projects, school_events, school_mobile, school_email, blog_body, icon_input, school_facility, icon_input_2, school_facility_2, icon_input_3, school_facility_3, icon_input_4, school_facility_4, icon_input_5, school_facility_5, icon_input_6, school_facility_6, icon_input_7, school_facility_7, icon_input_8, school_facility_8, icons_activities, school_activities_heading_1, school_activities_para_1, icons_activities_2, school_activities_heading_2, school_activities_para_2, icons_activities_3, school_activities_heading_3, school_activities_para_3, icons_mission, school_mission_heading, school_mission_para, icons_vision, school_vision_heading, school_vision_para, school_activities, school_mission_vision, blog_image, school_images, icon_social, school_instagram, icon_social_2, school_facebook, icon_social_3, school_twitter, category, author_id) VALUES('$title', '$tagline', '$rating', '$projects', '$events', '$mobile', '$email', '$body', '$icon', '$facility_1', '$icon2', '$facility_2', '$icon3', '$facility_3', '$icon4', '$facility_4', '$icon5', '$facility_5', '$icon6', '$facility_6', '$icon7', '$facility_7', '$icon8', '$facility_8', '$icon_activities', '$activities_heading_1', '$activities_para_1', '$icon_activities_2', '$activities_heading_2', '$activities_para_2', '$icon_activities_3', '$activities_heading_3', '$activities_para_3', '$icon_mission', '$mission_heading', '$mission_para', '$icon_vision', '$vision_heading', '$vision_para', '$activities', '$missionVision', '$filename', '$filename1', '$social_icon', '$social_icon_2', '$social_icon_3', '$instagram', '$facebook', '$twitter', '$category', '$author_id')";
$query4 = mysqli_query($config, $sql4);
// $sql3 = "INSERT INTO images(school_image) VALUES('$filename1')";
// $query3 = mysqli_query($config, $sql3);
if ($query4) {
$msg = ["Post Publish Successfully", "alert-success"];
$_SESSION['msg'] = $msg;
// If the post publish successfully then redirect to same page with success message.
header("location:add_blog.php");
} else {
$msg = ["Failed, Please try again", "alert-danger"];
$_SESSION['msg'] = $msg;
header("location:add_blog.php");
}
}
}
?>
Output Screenshot Error
I need a help regarding my source code on uploading and displaying the profile picture of my users on their profile.
The upload went smooth, but the display is not. The display of the user's picture is only shown in picture icon and not the real picture. Like this:
the file where the picture is stored is here
and here is my source code
edit-profile.php
<div class="author">
<a href="#">
<img class="avatar border-gray" src="../uploads/candidate/<?php echo $row['photo']; ?>" alt="..."/>
<h4 class="title"><?php echo $_SESSION['name']; ?><br /> </h4>
</a>
</div>
EDIT:
I'll provide the full source code for both userindex.php and edit-profile.php here so maybe any of you can point me where I do wrong.
userindex.php
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="header">
<h4 class="title">Edit Profile</h4>
</div>
<div class="content">
<form action="update-profile.php" method="post" enctype="multipart/form-data">
<?php
//Sql to get logged in user details.
$sql = "SELECT * FROM users WHERE id_user='$_SESSION[id_user]'";
$result = $conn->query($sql);
//If user exists then show his details.
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="user_name" type="text" id="user_name"> Full Name</label>
<input name="user_name" class="form-control" type="text" maxlength="100" value="<?php echo $row['user_name'] ?>" required=""/>
</div>
</div>
</div>
<!-- section 1-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="ic_no" type="text" id="ic_no" maxlength="12">NRIC</label>
<input name="ic_no"type="text" class="form-control" value="<?php echo $row['ic_no'] ?>" readonly>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="nationality" type="text" id="nationality">Nationality</label>
<input name="nationality" class="form-control" type="text" id="nationality" value="<?php echo $row['nationality'] ?>"/>
</div>
</div>
</div>
<!--first section -->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="gender" type="text" id="gender">Gender</label>
<input name="gender" class="form-control" type="text" id="gender" value="<?php echo $row['gender'] ?>"/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="race" type="text" id="race">Race</label>
<input type="text" class="form-control" name="race" id="race" value="<?php echo $row['race'] ?>"/>
</div>
</div>
</div>
<!-- second section -->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="contactno" type="text" id="contact_no">Contact No</label>
<input name="contactno" class="form-control" type="text" id="contact_no" value="<?php echo $row['contactno'] ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="email" type="text" id="email">Email</label>
<input type="text" class="form-control" type="text" id="email" value="<?php echo $row['email'] ?>" readonly>
</div>
</div>
</div>
<!--other add -->
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="address" type="text" id="address">Current Address</label>
<textarea id="address" name="address" class="form-control" rows="5" placeholder="Address"><?php echo $row['address']; ?></textarea>
</div>
</div>
</div>
<!-- third section -->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="highest_qualification" type="text" id="highest_qualification">Highest Qualification</label>
<input name="highest_qualification" class="form-control" type="text" maxlength="100" value="<?php echo $row['highest_qualification'] ?>"/>
</div>
</div>
</div>
<!--another section -->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="university" type="text" id="university">University</label>
<input name="university" class="form-control" type="text" maxlength="100" value="<?php echo $row['university'] ?>"/>
</div>
</div>
</div>
<!--another section -->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="major" type="text" id="major">Major</label>
<input name="major" class="form-control" type="text" maxlength="100" value="<?php echo $row['major'] ?>"/>
</div>
</div>
</div>
<!-- another section-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="current_position" type="text" id="current_position">Current Position</label>
<input type="text" class="form-control" name="current_position" value="<?php echo $row['current_position'] ?>"/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="position_appled" type="text" id="position_applied">Position Applied</label>
<input type="text" class="form-control" name="position_applied" value="<?php echo $row['position_applied'] ?>">
</div>
</div>
</div>
<!--another section -->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="current_monthly_salary" type="text" id="current_monthly_salary">Current Monthly Salary</label>
<input type="text" class="form-control" name="current_position" value="<?php echo $row['current_monthly_salary'] ?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="expected_monthly_salary" type="text" id="expected_monthly_salary">Expected Monthly Salary</label>
<input type="text" class="form-control" name="position_applied" value="<?php echo $row['expected_monthly_salary'] ?>">
</div>
</div>
</div>
<!--another section -->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="prefered_working_location" type="text" id="prefered_working_location">Prefered Working Location</label>
<input name="prefered_working_location" class="form-control" type="text" maxlength="100" value="<?php echo $row['prefered_working_location'] ?>" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="avaibility" type="text" id="avaibility">Avaibility</label>
<select name = "avaibility" class="form-control " type="text" id="avaibility" value="<?php echo $row['avaibility'] ?>">
<option value="">-- select one --</option>
<option value="Immediately">Immediately</option>
<option value="One Month">One Month</option>
<option value="Two Month">Two Month</option>
<option value="Three Month">Three Month</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="language" type="text" id="language">Language Proficiency</label><br />
   <p>Proficiency level 0-poor; 10-excellent</p>
<table border="2" bordercolor="gray" align="center">
<tr>
<td>
<label for="malay" type="text" id="malay" placeholder="Malay" style="color:black; width:200px"><b>Malay</b></label><br />
</td>
<td>
<input name="malay" type="text" class="form-control" maxlength="100" style="width: 200px" value="<?php echo $row['malay'] ?>"/>
</td>
</tr>
<tr>
<td>
<label for="english" type="text" id="english" placeholder="English" style="color:black; width:200px"><b>English</b></label><br />
</td>
<td>
<input name="english" type="text" class="form-control" maxlength="100" style="width: 200px" value="<?php echo $row['english'] ?>"/>
</td>
</tr>
<tr>
<td>
<label for="mandarin" type="text" id="mandarin" placeholder="Mandarin" style="color:black; width:200px"><b>Mandarin</b></label><br />
</td>
<td>
<input name="mandarin" type="text" class="form-control" maxlength="100" style="width: 200px" value="<?php echo $row['mandarin'] ?>"/>
</td>
</tr>
<tr>
<td>
<label for="other" type="text" id="other" placeholder="Other" style="color:black; width:200px"><b>Others</b></label><br />
</td>
<td>
<input name="other" type="text" class="form-control" maxlength="100" style="width: 200px" value="<?php echo $row['other'] ?>"/>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="aboutme" type="text" id="aboutme"><b>About Me</b></label><br />
<p>Summarize your employement history (Not more than 100 words)</p>
<textarea class="form-control" rows="6" id="aboutme" name="aboutme" maxlength="400" style="width: 560px"value="<?php echo $row['aboutme'] ?>"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label style="color:black;">Latest passport photo</label>
<input class="btn btn-danger" type="file" name="image" id="profile-img" /><br>
<img src="../uploads/candidate/<?php echo $row['photo']; ?>" id="profile-img-tag" width="200px" />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label style="color:black;">File format PDF and doc only!</label>
<input type="file" name="resume" class="btn btn-danger" />
</div>
</div>
</div>
<button type="submit" class="btn btn-info btn-fill pull-right">Update Profile</button>
<div class="clearfix"></div>
<?php
}
}
?>
</form>
<?php if(isset($_SESSION['uploadError'])) { ?>
<div class="row">
<div class="col-md-12 text-center">
<?php echo $_SESSION['uploadError']; ?>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<!--second part of picture and resume -->
<div class="col-md-4">
<div class="card card-user">
<div class="image">
<img src="https://ununsplash.imgix.net/photo-1431578500526-4d9613015464?fit=crop&fm=jpg&h=300&q=75&w=400" alt="..."/>
</div>
<div class="content">
<div class="author">
<a href="#">
<img class="avatar border-gray" src="../uploads/candidate/<?php echo $row['photo']; ?>" alt="..."/>
<h4 class="title"><?php echo $_SESSION['name']; ?><br /> </h4>
</a>
</div>
</div>
<hr>
<div class="text-center">
<button href="#" class="btn btn-simple"><i class="fa fa-facebook-square"></i></button>
<button href="#" class="btn btn-simple"><i class="fa fa-twitter"></i></button>
<button href="#" class="btn btn-simple"><i class="fa fa-google-plus-square"></i></button>
</div>
</div>
</div>
</div>
</div>
and this is update-profile.php
<?php
//To Handle Session Variables on This Page
session_start();
if(empty($_SESSION['id_user'])) {
header("Location: ../index.php");
exit();
}
//Including Database Connection From db.php file to avoid rewriting in all files
require_once("../db.php");
//if user Actually clicked update profile button
if(isset($_POST)) {
//Escape Special Characters
if(isset($_POST)) {
$user_name = mysqli_real_escape_string($conn, $_POST['user_name']);
$ic_no = mysqli_real_escape_string($conn, $_POST['ic_no']);
$nationality = mysqli_real_escape_string($conn, $_POST['nationality']);
$gender = mysqli_real_escape_string($conn, $_POST['gender']);
$race = mysqli_real_escape_string($conn, $_POST['race']);
$ic_no = mysqli_real_escape_string($conn, $_POST['ic_no']);
$contactno = mysqli_real_escape_string($conn, $_POST['contactno']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$address = mysqli_real_escape_string($conn, $_POST['address']);
$highest_qualification = mysqli_real_escape_string($conn, $_POST['highest_qualification']);
$university = mysqli_real_escape_string($conn, $_POST['university']);
$major = mysqli_real_escape_string($conn, $_POST['major']);
$current_position = mysqli_real_escape_string($conn, $_POST['current_position']);
$position_applied = mysqli_real_escape_string($conn, $_POST['position_applied']);
$current_monthly_salary = mysqli_real_escape_string($conn, $_POST['current_monthly_salary']);
$expected_monthly_salary = mysqli_real_escape_string($conn, $_POST['expected_monthly_salary']);
$prefered_working_location = mysqli_real_escape_string($conn, $_POST['prefered_working_location']);
$avaibility = mysqli_real_escape_string($conn, $_POST['avaibility']);
$malay = mysqli_real_escape_string($conn, $_POST['malay']);
$english = mysqli_real_escape_string($conn, $_POST['english']);
$mandarin = mysqli_real_escape_string($conn, $_POST['mandarin']);
$other = mysqli_real_escape_string($conn, $_POST['other']);
$aboutme = mysqli_real_escape_string($conn, $_POST['aboutme']);
$uploadOk = true;
if(isset($_FILES)) {
$folder_dir = "../uploads/resume/";
$base = basename($_FILES['resume']['name']);
$resumeFileType = pathinfo($base, PATHINFO_EXTENSION);
$file = uniqid() . "." . $resumeFileType;
$filename = $folder_dir .$file;
if(file_exists($_FILES['resume']['tmp_name'])) {
if($resumeFileType == "pdf") {
if($_FILES['resume']['size'] < 500000) { // File size is less than 5MB
move_uploaded_file($_FILES["resume"]["tmp_name"], $filename);
} else {
$_SESSION['uploadError'] = "Wrong Size. Max Size Allowed : 5MB";
header("Location: edit-profile.php");
exit();
}
} else {
$_SESSION['uploadError'] = "Wrong Format. Only PDF Allowed";
header("Location: edit-profile.php");
exit();
}
}
} else {
$uploadOk = false;
}
//Update User Details Query
$sql= "UPDATE users set user_name='$user_name', ic_no='$ic_no', gender='$gender', nationality='$nationality', race='$race', email='$email', contactno='$contactno', highest_qualification='$$highest_qualification',
university='$university', major='$major', current_position='$current_position', position_applied='$position_applied', current_monthly_salary='$current_monthly_salary',
expected_monthly_salary='$expected_monthly_salary', prefered_working_location='$prefered_working_location', avaibility='$avaibility', malay='$malay', english='$english',
mandarin='$mandarin', other='$other', photo='$file', resume='$file', aboutme='$aboutme'";
if($uploadOk == true) {
$sql .= ", resume='$file'";
}
$sql .= " WHERE id_user='$_SESSION[id_user]'";
if($conn->query($sql) === TRUE) {
$_SESSION['user_name'] = $user_name;
//If data Updated successfully then redirect to dashboard
header("Location: index.php");
exit();
} else {
echo "Error ". $sql . "<br>" . $conn->error;
}
//Close database connection. Not compulsory but good practice.
$conn->close();
} else {
//redirect them back to dashboard page if they didn't click update button
header("Location: edit-profile.php");
exit();
}};
Check your update-profile.php
There's confusion happened there because you put the same 'file name' for both your file type for image and resume. You should do it like this instead
<?php
//To Handle Session Variables on This Page
session_start();
if(empty($_SESSION['id_user'])) {
header("Location: ../index.php");
exit();
}
//Including Database Connection From db.php file to avoid rewriting in all files
require_once("../db.php");
//if user Actually clicked update profile button
if(isset($_POST)) {
//Escape Special Characters
if(isset($_POST)) {
$user_name = mysqli_real_escape_string($conn, $_POST['user_name']);
$ic_no = mysqli_real_escape_string($conn, $_POST['ic_no']);
$nationality = mysqli_real_escape_string($conn, $_POST['nationality']);
$gender = mysqli_real_escape_string($conn, $_POST['gender']);
$race = mysqli_real_escape_string($conn, $_POST['race']);
$ic_no = mysqli_real_escape_string($conn, $_POST['ic_no']);
$contactno = mysqli_real_escape_string($conn, $_POST['contactno']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$address = mysqli_real_escape_string($conn, $_POST['address']);
$highest_qualification = mysqli_real_escape_string($conn, $_POST['highest_qualification']);
$university = mysqli_real_escape_string($conn, $_POST['university']);
$major = mysqli_real_escape_string($conn, $_POST['major']);
$current_position = mysqli_real_escape_string($conn, $_POST['current_position']);
$position_applied = mysqli_real_escape_string($conn, $_POST['position_applied']);
$current_monthly_salary = mysqli_real_escape_string($conn, $_POST['current_monthly_salary']);
$expected_monthly_salary = mysqli_real_escape_string($conn, $_POST['expected_monthly_salary']);
$prefered_working_location = mysqli_real_escape_string($conn, $_POST['prefered_working_location']);
$avaibility = mysqli_real_escape_string($conn, $_POST['avaibility']);
$malay = mysqli_real_escape_string($conn, $_POST['malay']);
$english = mysqli_real_escape_string($conn, $_POST['english']);
$mandarin = mysqli_real_escape_string($conn, $_POST['mandarin']);
$other = mysqli_real_escape_string($conn, $_POST['other']);
$aboutme = mysqli_real_escape_string($conn, $_POST['aboutme']);
$uploadOk = true;
if(isset($_FILES)) {
$folder_dir = "../uploads/resume/";
$base = basename($_FILES['resume']['name']);
$resumeFileType = pathinfo($base, PATHINFO_EXTENSION);
//notice that I changed your file name from $file to $file1
$file1 = uniqid() . "." . $resumeFileType;
$filename = $folder_dir .$file1;
if(file_exists($_FILES['resume']['tmp_name'])) {
if($resumeFileType == "pdf") {
if($_FILES['resume']['size'] < 500000) { // File size is less than 5MB
move_uploaded_file($_FILES["resume"]["tmp_name"], $filename);
} else {
$_SESSION['uploadError'] = "Wrong Size. Max Size Allowed : 5MB";
header("Location: edit-profile.php");
exit();
}
} else {
$_SESSION['uploadError'] = "Wrong Format. Only PDF Allowed";
header("Location: edit-profile.php");
exit();
}
}
} else {
$uploadOk = false;
}
//image update edit
if(is_uploaded_file ( $_FILES['image']['tmp_name'] )) {
$folder_dir = "../uploads/logo/";
$base = basename($_FILES['image']['name']);
$imageFileType = pathinfo($base, PATHINFO_EXTENSION);
$file = uniqid() . "." . $imageFileType;
$filename = $folder_dir .$file;
if(file_exists($_FILES['image']['tmp_name'])) {
if($imageFileType == "jpg" || $imageFileType == "png") {
if($_FILES['image']['size'] < 500000) { // File size is less than 5MB
//If all above condition are met then copy file from server temp location to uploads folder.
move_uploaded_file($_FILES["image"]["tmp_name"], $filename);
} else {
$_SESSION['uploadError'] = "Wrong Size. Max Size Allowed : 5MB";
header("Location: edit-profile.php");
exit();
}
} else {
$_SESSION['uploadError'] = "Wrong Format. Only jpg & png Allowed";
header("Location: edit-profile.php");
exit();
}
}
} else {
$uploadOk = false;
}
//Update User Details Query
$sql= "UPDATE users set user_name='$user_name', ic_no='$ic_no', gender='$gender', nationality='$nationality', race='$race', email='$email', contactno='$contactno', highest_qualification='$$highest_qualification',
university='$university', major='$major', current_position='$current_position', position_applied='$position_applied', current_monthly_salary='$current_monthly_salary',
expected_monthly_salary='$expected_monthly_salary', prefered_working_location='$prefered_working_location', avaibility='$avaibility', malay='$malay', english='$english',
mandarin='$mandarin', other='$other', logo='$file', resume='$file1', aboutme='$aboutme'";
if($uploadOk == true) {
$sql .= ", resume='$file'";
}
$sql .= " WHERE id_user='$_SESSION[id_user]'";
if($conn->query($sql) === TRUE) {
$_SESSION['user_name'] = $user_name;
//If data Updated successfully then redirect to dashboard
header("Location: edit-profile.php");
exit();
} else {
echo "Error ". $sql . "<br>" . $conn->error;
}
//Close database connection. Not compulsory but good practice.
$conn->close();
} else {
//redirect them back to dashboard page if they didn't click update button
header("Location: edit-profile.php");
exit();
}};
I have tried your previous code, that cause the image to be stored as pdf and that's why when you call for the image to be displayed, it's appears as broken image icon instead. I hope this can help you well and good luck!
Try this code
<img src="uploads/candidate/.'<?php echo row['photo']; ?>'"/>
You need to make sure the $row value actually got value.
try this and see if you got any result:
die(var_dump("../uploads/candidate/".$row['photo'] ));
You will get the path the code is refering to, if that doesn't give a result check your query again ( check if the row got value )
You can do this introducing an external php file e.g get.php, then request the photo from this get.php.
See sample of both files below.
display.php file
<?php
$id = row['id'];
<img class="avatar" src=get.php?id=$id alt="profile photo" />
?>
get.php file
<?php
// make connections with database here
$id = $_REQUEST['id'];
$image = ("SELECT * FROM table WHERE id = '$id'");
$image = $image->fetch_assoc();
$image = $image['photo'];
echo $image;
?>
You have problem in your $_SESSION array userindex.php file. You have missed the quites ' for session key
$sql = "SELECT * FROM users WHERE id_user='$_SESSION[id_user]'";
So assign it to a variable first and then put that variable inside sql query
$id_user = $_SESSION['id_user'];// single quotes for session key
$sql = "SELECT * FROM users WHERE id_user='$id_user'";
Note:
Your code is open to sql injections. Try use PDO or prepared statements