1

I have this html form

<form action="insert.php" method="post" enctype="multipart/form-data">>
<p>
    <label for="covername">Cover Artwork:</label>
    <input type="file" name="file"/>
</p>
<p>
    <label for="textname">Text Artwork:</label>
    <input type="file" name="textname"/><br><br>
</p>

<input type="submit" name="submit" value="Upload"/>

and this is the insert.php

//Upload cover artwork
$name= $_FILES['file']['name'];
$tmp_name= $_FILES['file']['tmp_name'];
$submitbutton= $_POST['submit'];
$position= strpos($name, "."); 
$fileextension= substr($name, $position + 1);
$fileextension= strtolower($fileextension);

if (isset($name)) {

$path= 'uploads/';

if (!empty($name)){
if (move_uploaded_file($tmp_name, $path.$name)) {
echo 'Uploaded!';

}
}
}


//Upload text artwork
$textname= $_FILES['file']['textname'];
$tmp_textname= $_FILES['file']['tmp_textname'];
$textsubmitbutton= $_POST['submit'];
$textposition= strpos($textname, "."); 
$textfileextension= substr($textname, $textposition + 1);
$textfileextension= strtolower($textfileextension);

if (isset($textname)) {

$textpath= 'uploads/';

if (!empty($textname)){
if (move_uploaded_file($tmp_textname, $textpath.$textname)) {
echo 'Uploaded!';

}
}
}

// attempt insert query execution
$sql = "INSERT INTO table (covername, textname) VALUES ('$name', '$textname')";
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);
?>

The covername is saved to the database and the file is uploaded to uploads/ - this works great. But the second upload isn't working at all, textname isn't saved to the db nor is it uploaded. What am i missing?

4
  • There are any errors??? Commented Feb 21, 2018 at 10:41
  • StackOverflow-What does for attribute do in html label tag Seems like the for attribute in label must match the id attribute of the input. Consider configuring Xdebug to debug the php script. XDebug Commented Feb 21, 2018 at 10:48
  • i think you are upload image with text name? or you trying to add two image ? Commented Feb 21, 2018 at 10:55
  • 1
    This is a straight pick from the documentation $_FILES in PHP. name and tmp_name are fields available for each file in the superglobal $_FILES. The respective file needs to be accessed by $_FILES["html_input_name"]. Commented Feb 21, 2018 at 11:01

1 Answer 1

1

Just change this:

//Upload text artwork
$textname= $_FILES['textname']['name'];
$tmp_textname= $_FILES['textname']['tmp_name'];
$textsubmitbutton= $_POST['submit'];
$textposition= strpos($textname, "."); 
$textfileextension= substr($textname, $textposition + 1);
$textfileextension= strtolower($textfileextension);

if (isset($textname)) {

$textpath= 'uploads/';

if (!empty($textname)){
if (move_uploaded_file($tmp_textname, $textpath.$textname)) {
echo 'Uploaded!';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.