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?

Salim Ibrohimi
  • 1,351
  • 3
  • 17
  • 35
99ajohnson
  • 83
  • 9
  • There are any errors??? – Salim Ibrohimi Feb 21 '18 at 10:41
  • [StackOverflow-What does for attribute do in html label tag](https://stackoverflow.com/questions/18432376/what-does-for-attribute-do-in-html-label-tag#18432439) Seems like the _for_ attribute in label must match the _id_ attribute of the input. Consider configuring Xdebug to debug the php script. [XDebug](https://xdebug.org/) – Sameer Achanta Feb 21 '18 at 10:48
  • i think you are upload image with text name? or you trying to add two image ? – Ismail Altunören Feb 21 '18 at 10:55
  • 1
    This is a straight pick from the documentation [$_FILES in PHP](https://secure.php.net/manual/de/reserved.variables.files.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"]. – Sameer Achanta Feb 21 '18 at 11:01

1 Answers1

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!';
Salim Ibrohimi
  • 1,351
  • 3
  • 17
  • 35