I am Uploading the Files through Simple Form of HTML using Php & MySQL. When i upload the Any File or Image it can be moved to its folder successfully but the name of File or Image is not showing in Database Table. What is this problem ?
This is my code you can check if any mistake is found:
enter code <?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "imycro");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$name = mysqli_real_escape_string($link, $_POST['name']);
$email = mysqli_real_escape_string($link, $_POST['email']);
$country = mysqli_real_escape_string($link, $_POST['country']);
$phone = mysqli_real_escape_string($link, $_POST['phone']);
$city = mysqli_real_escape_string($link, $_POST['city']);
$summary = mysqli_real_escape_string($link, $_POST['summary']);
$jobtype = mysqli_real_escape_string($link, $_POST['jobtype']);
if(isset($_FILES["cv"]["error"])){
if($_FILES["cv"]["error"] > 0){
echo "Error: " . $_FILES["cv"]["error"] . "<br>";
} else{
$allowed = array("jpg" => "image/jpg", "jpeg" => "image/jpeg", "gif" => "image/gif", "png" => "image/png");
$filename = $_FILES["cv"]["name"];
$filetype = $_FILES["cv"]["type"];
$filesize = $_FILES["cv"]["size"];
// Verify file extension
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!array_key_exists($ext, $allowed)) die("Error: Please select a valid file format.");
// Verify file size - 5MB maximum
$maxsize = 5 * 1024 * 1024;
if($filesize > $maxsize) die("Error: File size is larger than the allowed limit.");
// Verify MYME type of the file
if(in_array($filetype, $allowed)){
// Check whether file exists before uploading it
if(file_exists("Documents/" . $_FILES["cv"]["name"])){
echo $_FILES["cv"]["name"] . " is already exists.";
} else{
move_uploaded_file($_FILES["cv"]["tmp_name"], "Documents/" . $_FILES["cv"]["name"]);
echo "Your file was uploaded successfully.";
}
} else{
echo "Error: There was a problem uploading your file - please try again.";
}
}
} else{
echo "Error: Invalid parameters - please contact your server administrator.";
}
// FILE UPLOAD CODE ENDS HERE /////////////////////////////
// attempt insert query execution
$sql = "INSERT INTO work (name, email, country, phone, city, summary, jobtype) VALUES ('$name', '$email', '$country' , '$phone' , '$city', '$summary' , '$jobtype')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>