Hello everyone!
I’m looking for a simple bit of help…
This is my script (the action of a form submit) that uploads a file to my server.
[code=php]<?php
include(‘config.php’);
//Connect to database
$cxn = mysqli_connect($host, $username, $password, ********) or die (“No connection can be made.”);
//Get the parent’s ID number.
$fID = $_GET[‘fID’];
//Get the variables from our modFile form.
$title=$_POST[‘title’];
$desc=$_POST[‘desc’];
$fGenre=$_POST[‘fGenre’];
//Get the user’s name for proper credit.
$userName=$_SESSION[‘name’];
// Get the file name and add “m” for MOD file.
$file_name = $_FILES[‘modFile’][‘name’];
$uploadLetter=m;
// Random 7 digit number to add to our file name
$random_digit=rand(0000000000,9999999999);
//Here’s how we create the new file name.
$new_file_name=$uploadLetter.$random_digit.$file_name;
//set where you want to store files
$path= “files/fileUploads/mods/”.$new_file_name;
if($modFile !=none)
{
if(move_uploaded_file($_FILES[‘modFile’][‘tmp_name’], $path))
{
echo “Successful<BR/>”;
echo “File Name :”.$new_file_name.”<BR/>”;
echo “File Size :”.$_FILES[‘modFile’][‘size’].”<BR/>”;
echo “File Type :”.$_FILES[‘modFile’][‘type’].”<BR/>”;
}
else
{
echo “Error”;
}
}
mysqli_query($cxn, “INSERT INTO fileAlt (parent, fileName, desc, fileGenre, uploader, filePath) VALUES (‘$fID’, ‘$title’, ‘$desc’, ‘$fGenre’, ‘$userName’, ‘$path’)”) or die (‘FAILED.’);
?>
The files upload properly, but no information is stored in the database, and I get the die error ‘FAILED’.
Could anyone help me correct this script? I’m sure the solution is fairly obvious, but I’m still learning and have tried so many INSERT statement configurations that haven’t worked.
Thanks!