Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:18:28+00:00 2026-06-17T20:18:28+00:00

I’ve looked at many other posts about this same problem, but I still can’t

  • 0

I’ve looked at many other posts about this same problem, but I still can’t seem to find out what is wrong with my code. Mind you, I started learning PHP and SQL this week, so please excuse me if I made a stupid mistake. Also, I’m sure it’s worth noting that before the error message that is posted in the title appeared, there was another error (defined in my code). That error was:

” already exists.”

That tells me that the $_POST["file"]["name"] variable is not set for whatever reason. Any help is appreciated. However, if you are going to tell me that my code is vulnerable to SQL injection, I know that. The upload script is only accessible through my (secure) login script. Again, all help is welcome!

<?php
  /* Process uploaded file */

if ($_FILES["file"]["size"] < 2097152)
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
      if (file_exists($_POST["class"] . "/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists.";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
        $_POST["class"] . "/" . $_FILES["file"]["name"]);
        $newpath = mysql_real_escape_string("uploads/" . $_POST['class'] . "/" . $_FILES['file']['name']);
        $filename = mysql_real_escape_string($_FILES['file']['name']);
        $description = mysql_real_escape_string($_POST["description"]);
        echo "Stored in: " . $newpath;
      }
    }
  }
else
  {
  echo "File must be less than two megabytes.";
  }

  /* Create and store information in MySQL Database */

  $con = mysql_connect("localhost","user","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("1169030_dsp", $con);

$sql="INSERT INTO $_POST[class] (Description, Filename, File)
VALUES
  ('$description','$filename','$newpath')";


if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Your file was successfully uploaded.";

mysql_close($con);
?>

Here is my input form HTML:

  <center>
    <form action="uploadfile.php" method="post" style="background-color:#009933;color:#FFFFFF;width:320px;text-align:left;">
  Description: <input type="text" name="description"><br>
  File:        <input type="file" name="file"><br>
      Class:<br>
  <Select name="Class">
    <option value="period1">APES : period1</option>
    <option value="period2">Chemistry I : period2</option>
    <option value="period3">Lab Assist/Sci : period 3</option>
    <option value="period4">Lab Assist/Sci : period 4</option>
    <option value="period4">APES : period 4</option>
    <option value="period5">APES : period 5</option>
    <option value="period6">Lab Assist/Sci : period 6</option>
    <option value="period7">Chemistry I : period 7</option>
  </Select><br>
      <input type="submit" name="Upload">
</form>
  <center>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:18:30+00:00Added an answer on June 17, 2026 at 8:18 pm

    Your problem is that your form does not have the enctype attribute set. It should be:

    <form action="uploadfile.php" method="post" enctype="multipart/form-data" style="background-color:#009933;color:#FFFFFF;width:320px;text-align:left;">
    

    enctype="multipart/form-data" is required for $_FILES to be populated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there's a lot of other questions out there that deal with this
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.