File Upload don't work
Discuss coding issues, and scripts related to PHP and MySQL.
-
mlucicom
- Posts: 37
File Upload don't work
Hello! i have a script that insert some details in MySql database but the file upload don't work.Have you any ideea why don't work ?
Code: Select all
if(isset($_POST['submit']))
{
// get values form input text and number
$id = trim($_GET['id']);
$subiect = $_POST['motiv'];
$mesaj = $_POST['coment'];
$contact = $_POST['perioada'];
$data = date('m/d/Y');
$target = "images/";
$fileName = $_FILES['Filename']['name'];
$fileTarget = $target.$fileName;
$tempFileName = $_FILES["Filename"]["tmp_name"];
$fileDescription = $_POST['Description'];
$result = move_uploaded_file($tempFileName,$fileTarget);
/*
* If file was successfully uploaded in the destination folder
*/
if($result) { echo "FIle uploaded";
}
// mysql query to insert data
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO contact2 (location,subiect,mesaj,imagine,contact,data)
VALUES ('$id', '$subiect','$mesaj','$fileName','$contact','$data')";
if ($conn->query($sql) === TRUE) {
$last_id = $conn->insert_id;
echo "Your message was se";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
Admin
Hello
I not know what problem you have with that script. Does it not put the file on server, or does it not insert data in mysql?
It might be problem from the html form, or the column types in mysql, or variable with data for inserting in mysql is not defined.
Check with " echo $sql; " to see if the resulted sql query string is ok, with all necessary data. Then, you can copy and test the sql query in phpmyadmin.
Also, you can use this code at the beginning of the script, it sets php to display its errors:
Code: Select all
ini_set('display_errors',1);
error_reporting(E_ALL);
mlucicom
Hello! The script don't upload the file and don't insert the image Patch in database
Admin
I not know whay it not works, it might be problem from the html form, or the column types in mysql, or variable with data for inserting in mysql is not defined.
If there is no error, try add: echo $sql; to see if all data are properly added in that sql query.
Also, the directory where you want to upload the files must have CHMOD 0755 (or 0777) to allow php write files in it.
Similar Topics
-
Make regex replace() work on all matches
JavaScript - jQuery - Ajax
First post
I’m trying to replace all spaces within a string with hyphens.
I tried this:
let str ='This is my text';
str = str.replace(/\s/, '-');...
Last post
Add the global search flag (/g ) to your regex to match all occurrences.
let str ='This is my text';
str = str.replace(/\s/g, '-');...
-
Multiple select for upload not working on mobile
JavaScript - jQuery - Ajax
First post
Plessant Coursesweb,
meight useless to ask but it seems this upload for picture-album is not working on my mobile-page
but on my computer I just...
Last post
Try to search on the internet for:
html multiple select upload mobile
-
Access an XML file from different domain in JS
JavaScript - jQuery - Ajax
First post
I am creating a website with HTML and JavaScript that relies on the data of an XML file hosted on a separate domain.
I can achieve this with...
Last post
Try using the the fetch api.
fetch('//example.com/file_address')
.then( response => response.text() )
.then( response => {
//response is...