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

  • SEARCH
  • Home
  • 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 8311625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:52:44+00:00 2026-06-08T19:52:44+00:00

I am having trouble getting the image upload feature to work on the code

  • 0

I am having trouble getting the image upload feature to work on the code below with the following error meesage:

‘An error occurred in script ‘/database.php’ on line 135:
Undefined index: image’

which is this part: ‘if (is_uploaded_file ($_FILES [‘image’][‘tmp_name’])) {‘

I’ve done a few php/mysql forms before but this is the first time I’ve tried to use image uploads. If possible I’m after a form that allows pdfs and jpegs only and limits the upload to 1.5 meg.

The rest of the form works ok, other than that, I have changed the CHMOD to 777 on the uploads folder on the server. Any ideas or suggestions?

<?php # index.php
require_once ('./includes/config.inc.php');
$page_title = 'N-Club Battery: Add a Sale';
include ('./includes/header.html');
if (!isset($_SESSION['sp_user_id'])) {
$url = 'http://' . $_SERVER['HTTP_HOST']
. dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1); // Chop off the slash.
}
$url .= '/login.php'; 
ob_end_clean(); // Delete the buffer.
header("Location: $url"); 
exit(); // Quit the script.
}
$users = $_SESSION['sp_user_id'];
?>
<h1>Heading</h1>
<?php
if (isset($_POST['submitted'])) {// Handle the form.
require_once ('/database.php');
$errors = array(); // Initialize error array.

// Check for a quantity.
if (empty($_POST['npc_quantity'])) {
$errors[] = '<p>• You forgot to enter the Quantity.</p>';
} else {
$quantity = escape_data($_POST['npc_quantity']);
}

// Check for a customer name.
if (empty($_POST['npc_customer_name'])) {
$errors[] = '<p>• You forgot to enter the Customer Name</p>';
} else {
$customers = escape_data($_POST['npc_customer_name']);
}

// Check for an registration number
if (empty($_POST['npc_registration_no'])) {
$errors[] = '• You forgot to enter the Customer Rego Number.';
} else {
$rego = escape_data($_POST['npc_registration_no']);
}

// Check for an SUO number
if (empty($_POST['npc_suo_no'])) {
$errors[] = '• You forgot to enter the SUO Number';
} else {
$suo_no = escape_data($_POST['npc_suo_no']);
}

// Check for an A-Club number
if (empty($_POST['npc_amb_club_no'])) {
$errors[] = '• You forgot to enter the A-Club Number';
} else {
$amb_no = escape_data($_POST['npc_amb_club_no']);
}

// Check for a Repair Order
if (empty($_POST['npc_repair_order'])) {
$errors[] = '• You forgot to enter the Repair Order';
} else {
$rep_no = escape_data($_POST['npc_repair_order']);
}

// Check for a Invoice Number.
if (empty($_POST['npc_invoice_no'])) {
$errors[] = '<p>• You forgot to enter the Invoice Number.</p>';
} else {
$inv = escape_data($_POST['npc_invoice_no']);
}

// Check for a userdate.
if (empty($_POST['npc_entry_userdate'])) {
$errors[] = '<p>• You forgot to enter the entry userdate.</p>';
} else {
$inv_date = escape_data($_POST['npc_entry_userdate']);
}

// Check for an image.
if (is_uploaded_file ($_FILES ['image']['tmp_name'])) {
if (move_uploaded_file($_FILES ['image']['tmp_name'], 
"/uploadsfolder/{$_FILES['image']['name']}")) { // Move the file over.

echo '<p>The file has been uploaded!</p>';

} else { // Couldn't move the file over.
echo '<p><font color="red"> The thumbnail image could not be uploaded.</font></p>';
$i = FALSE;
}
$i = $_FILES['image']['name'];
} else {
$i = FALSE;
}

if (empty($errors)) { 

$uid = @mysql_insert_id(); 

// Add the user.
$query = "INSERT INTO npc_sales_list 
(npc_item_id , sp_user_id, npc_battery_n_code, npc_battery_other_code, npc_quantity , 
npc_customer_name, npc_registration_no , npc_suo_no, npc_amb_club_no , npc_repair_order, 
npc_invoice_no, npc_entry_userdate, npc_image_upload, npc_usertype, 
npc_points, npc_bonus_points, npc_entry_date) VALUES
('$uid', '$users', '$_POST[npc_battery_n_code]' , 
'$_POST[npc_battery_other_code]' , '$quantity' , '$customers', 
'$rego' , '$suo_no' , '$amb_no', '$rep_no', '$inv', '$inv_date', 
'$i' , Battery' , '5' , '0' , NOW())";
$result = @mysql_query ($query); // Run the query.

if (mysql_affected_rows() == 1) {

//Finish the page.
echo '<p>The sale with invoice number: <strong>' . $inv . '</strong><br />
is now registered into the system.</p>';
include ('./includes/footer.html'); // Include the HTML footer.
exit();

} else { // If it did not run OK.
echo '<p><font color="red" size="+1">You could not be
registered due to a system error. We apologize for any
inconvenience.</font></p>';
}

} else { // If one of the data tests failed.
echo '<p><font color="red" size="+1">Please check all mandatory fields are complete and try again.
</font></p>';
}

mysql_close(); // Close the database connection.

} // End of the main Submit conditional.
?>                          

<form action="logsales.php" method="post">

<table width="520" border="0" cellspacing="3" cellpadding="2">

<tr>
<td><div align="right">N-Club Battery No<span class="style2">*</span></div></td>
<td>            
<select  name="npc_battery_n_code" id="npc_battery_n_code">
<option value="None" <?php if (isset($_POST['npc_battery_n_code']) && $_POST['npc_battery_n_code'] == 'None') 
{echo 'selected="selected"';} ?>>None</option>
<option value="55D23L" <?php if (isset($_POST['npc_battery_n_code']) && $_POST['npc_battery_n_code'] == '55D23L') 
{echo 'selected="selected"';} ?>>55D23L</option>
<option value="55D23R" <?php if (isset($_POST['npc_battery_n_code']) && $_POST['npc_battery_n_code'] == '55D23R') 
{echo 'selected="selected"';} ?>>55D23R</option>                                
<option value="75D23R" <?php if (isset($_POST['npc_battery_n_code']) && $_POST['npc_battery_n_code'] == '75D23R') 
{echo 'selected="selected"';} ?>>75D23R</option>
</select>
</td>
</tr>  

<tr>
<td width="184"><div align="right">Other Battery No<span class="style2">*</span></div></td>
<td width="323">
<select  name="npc_battery_other_code" id="npc_battery_other_code">
<option value="None"  <?php if (isset($_POST['npc_battery_other_code']) && $_POST['npc_battery_other_code'] == 'None') 
{echo 'selected="selected"';} ?>>None</option>
<option value="3"  <?php if (isset($_POST['npc_battery_other_code']) && $_POST['npc_battery_other_code'] == '3') 
{echo 'selected="selected"';} ?>>3</option>
<option value="26" <?php if (isset($_POST['npc_battery_other_code']) && $_POST['npc_battery_other_code'] == '26') 
{echo 'selected="selected"';} ?>>26</option>                                                               
<option value="29" <?php if (isset($_POST['npc_battery_other_code']) && $_POST['npc_battery_other_code'] == '29') 
{echo 'selected="selected"';} ?>>29</option>
<option value="30" <?php if (isset($_POST['npc_battery_other_code']) && $_POST['npc_battery_other_code'] == '30') 
{echo 'selected="selected"';} ?>>30</option>
</select></td>
</tr>

<tr>
<td><div align="right">Quantity <span class="style2">*</span></div></td>
<td><input type="text" name="npc_quantity" size="10" maxlength="10" 
value="<?php if (isset($_POST['npc_quantity'])) echo $_POST['npc_quantity']; ?>" /></td>
</tr>

<tr>
<td><div align="right">Customer Name <span class="style2">*</span></div></td>
<td><input type="text" name="npc_customer_name" size="30" maxlength="30" 
value="<?php if (isset($_POST['npc_customer_name'])) echo $_POST['npc_customer_name']; ?>" /></td>
</tr>

<tr>
<td><div align="right">Customer Rego number <span class="style2">*</span></div></td>
<td><input type="text" name="npc_registration_no" size="10" maxlength="7" 
value="<?php if (isset($_POST['npc_registration_no'])) echo $_POST['npc_registration_no']; ?>" /></td>
</tr>

<tr>
<td><div align="right">SUO Number <span class="style2">*</span></div></td>
<td><input type="text" name="npc_suo_no" size="20" maxlength="30" 
value="<?php if (isset($_POST['npc_suo_no'])) echo $_POST['npc_suo_no']; ?>" /></td>
</tr>

<tr>
<td><div align="right">A-Club ID <span class="style2">*</span></div></td>
<td><input type="text" name="npc_amb_club_no" size="20" maxlength="30" 
value="<?php if (isset($_POST['npc_amb_club_no'])) echo $_POST['npc_amb_club_no']; ?>" /></td>
</tr>

<tr>
<td><div align="right">Repair Order<span class="style2">*</span></div></td>
<td><input type="text" name="npc_repair_order" size="20" maxlength="30" 
value="<?php if (isset($_POST['npc_repair_order'])) echo $_POST['npc_repair_order']; ?>" /></td>
</tr>


<tr>
<td><div align="right">Invoice Number <span class="style2">*</span></div></td>
<td><input type="text" name="npc_invoice_no" size="20" maxlength="30" 
value="<?php if (isset($_POST['npc_invoice_no'])) echo $_POST['npc_invoice_no']; ?>" /></td>
</tr>

<tr>
<td><div align="right">Date of Invoice <span class="style2">*</span></div></td>
<td><input type="text" name="npc_entry_userdate" size="20" maxlength="10" 
value="<?php if (isset($_POST['npc_entry_userdate'])) echo $_POST['npc_entry_userdate']; ?>" /></td>
</tr>

<tr>
<td></td>
<td>
<span class="sml_italics">MM-DD-YYYY </span></td>
</tr>

<tr>
<td><div align="right">Invoice copy<span class="style2">*</span></div></td>
<td> 
<input type="file" name="image"  size="30" maxlength="60" /> <br />
</td>
</tr>

<tr>
<td></td>
<td><input type="submit" name="submit" value="Submit" /></p><input type="hidden" name="submitted" value="TRUE" />
&nbsp;</td>
</tr>
</table>

</form>

<p>footer</p>

<?php
include ('./includes/footer.html');
?> 
  • 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-08T19:52:48+00:00Added an answer on June 8, 2026 at 7:52 pm

    Your <form> does not have an enctype attribute.

    <form action="logsales.php" method="post">
    

    It needs to be:

    <form action="logsales.php" method="post" enctype="multipart/form-data">
    

    Without it, your browser doesn’t know how to send the file to your server, so without the enctype, it won’t work. More information available at W3.

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

Sidebar

Related Questions

I'm having trouble getting the Jquery Cycle plugin to work. My code is below.
I'm having trouble getting a custom config section to work. It's some code I
I am having trouble getting the following code to render as I expect it
I am having trouble with this script. It's an image upload script and I
I'm having some trouble getting my buttons to work below a certain y value
I am having trouble getting a background-image to overlay the border of another div.
I'm having trouble getting the CanExecute method of my command to work property. I've
I'm currently having trouble getting example code for using tweepy to access Twitter's Streaming
I am having trouble getting my application to work correctly. I am trying to
Hey, so I'm having a bunch of trouble getting ExternalInterface to work, which is

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.