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 8332781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:49:14+00:00 2026-06-09T02:49:14+00:00

I have a site in which logged in users can log battery sales, but

  • 0

I have a site in which logged in users can log battery sales, but I am having a little trouble…

I have two questions:

  1. When I go to submit the form, Im getting a error message which reads ‘MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use’ which occurs just after the ‘INSERT INTO npc_sales_list’ query and have no idea why.

  2. I am also trying to validate the drop down menus (‘npc_battery_n_code’ and ‘npc_battery_other_code’) so that if a battery is selected in one drop down, the other will revert to ‘None’.

At the moment, if question number 1 can be answered ahead of 2 that would be great but any suggestions are welcome.

 <?php //logsale.php
 require_once ('./includes/config.inc.php');
 $page_title = 'Log a sale';
 include ('./includes/header.html');

 if (!isset($_SESSION['sp_user_id'])) {

 $url = 'http://' . $_SERVER['HTTP_HOST']
 . dirname($_SERVER['PHP_SELF']);
 // Check for a trailing slash.
 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 ('mydatabase.php');

 if (!empty($_POST['npc_quantity'])) {
 $quantity = escape_data($_POST ['npc_quantity']);
 } else {
 $quantity = FALSE;
 echo '<p><font color="red">You forgot to enter the Quantity</font></p>';
 }  

 if (!empty($_POST['npc_customer_name'])) {
 $customer = escape_data($_POST ['npc_customer_name']);
 } else {
 $customer = FALSE;
 echo '<p><font color="red">You forgot to enter the Customer Name</font></p>';
 }  

 if (!empty($_POST['npc_registration_no'])) {
 $rego = escape_data($_POST ['npc_registration_no']);
 } else {
 $rego = FALSE;
 echo '<p><font color="red">You forgot to enter the Customer Rego Number</font></p>';
 }  

 if (!empty($_POST['npc_suo_no'])) {
 $suo = escape_data($_POST ['npc_suo_no']);
 } else {
 $suo = FALSE;
 echo '<p><font color="red">You forgot to enter the SUO Number</font></p>';
 }  

 if (!empty($_POST['npc_amb_club_no'])) {
 $repair_order = escape_data($_POST ['npc_amb_club_no']);
 } else {
 $repair_order = FALSE;
 echo '<p><font color="red">You forgot to enter the A-Club number</font></p>';
 }  

 if (!empty($_POST['npc_repair_order'])) {
 $amb_club = escape_data($_POST ['npc_repair_order']);
 } else {
 $amb_club = FALSE;
 echo '<p><font color="red">You forgot to enter the Repair Order</font></p>';
 }  

 if (!empty($_POST['npc_invoice_no'])) {
 $inv = escape_data($_POST ['npc_invoice_no']);
 } else {
 $inv = FALSE;
 echo '<p><font color="red">You forgot to enter the Invoice Number </font></p>';
 }  

 if (!empty($_POST['npc_entry_userdate'])) {
 $inv_date = escape_data($_POST ['npc_entry_userdate']);
 } else {
 $inv_date = FALSE;
 echo '<p><font color="red">You forgot to enter the Invoice Date</font></p>';
 }

 if ($quantity && $customer && $rego && $suo && $repair_order && $amb_club && $inv && $inv_date)  {

 $uid = @mysql_insert_id(); //Get the url ID.
 $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_entry_userdate, npc_usertype, npc_points, npc_bonus_points, npc_entry_date)
 VALUES
 ('$uid', '$users', '$_POST[npc_battery_n_code]', '$_POST[npc_battery_other_code]', '$quantity',
 $customer , $rego, $suo, $amb_club , $repair_order, 
 $inv , 'NPC', '5' , '0' , NOW())";
 $result = mysql_query ($query) or trigger_error
 ("Query: $query\n<br />MySQL Error: " .mysql_error());

 if ($result = @mysql_query($query)) {

 //Finish the page.
 echo '<p>The sale with invoice number: <strong>' . $inv . '</strong>       <br />
 is now registered into the system.</p>
 <p>If you would like to log in further sales, please <a href="logsale.php">click here</a></p>
 <p>If you would like to view your sales log, please <a href="viewsales.php">click here</a></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 manatory fields are complete and try again.
 </font></p>';
 }

 mysql_close(); // Close the database connection.

 ?>                         


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


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

 <tr>
 <td width="184"><div align="right">NPC Vehicle<span class="style2">*</span></div></td>
 <td width="323"><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 <span class="style2">*</span></div></td>
 <td width="323">
 <select  name="npc_battery_other_code" id="npc_battery_other_code">
 <option value="50D20L" 
 <?php if (isset($_POST['npc_battery_other_code']) && $_POST['npc_battery_other_code'] == '50D20L') 
 {echo 'selected="selected"';} ?>>50D20L
 </option>
 <option value="50D20R" 
 <?php if (isset($_POST['npc_battery_other_code']) && $_POST['npc_battery_other_code'] == '50D20R') 
 {echo 'selected="selected"';} ?>>50D20R
 </option>
 <option value="55D23LMF" 
 <?php if (isset($_POST['npc_battery_other_code']) && $_POST['npc_battery_other_code'] == '55D23LMF') 
 {echo 'selected="selected"';} ?>>55D23LMF
 </option>
 <option value="55D23RMF" 
 <?php if (isset($_POST['npc_battery_other_code']) && $_POST['npc_battery_other_code'] == '55D23RMF') 
 {echo 'selected="selected"';} ?>>55D23RMF
 </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">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 No.<span class="style2">*</span></div></td>
 <td><input type="text" name="npc_suo_no" size="10" maxlength="7" 
 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="15" maxlength="7" 
 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="15" maxlength="12" 
 value="<?php if (isset($_POST['npc_repair_order'])) echo $_POST['npc_repair_order']; ?>" /></td>
 </tr>

 <tr>
 <td><div align="right">Invoice No. <span class="style2">*</span></div></td>
 <td><input size="10" name="npc_invoice_no" 
 value="<?php if (isset($_POST['npc_invoice_no'])) echo $_POST['npc_invoice_no']; ?>" /></td>
 </tr>

 <tr>
 <td><div align="right">Invoice Date <span class="style2">*</span></div></td>
 <td><input size="12" name="npc_entry_userdate" maxlength="10" 
 value="<?php if (isset($_POST['npc_entry_userdate'])) echo $_POST['npc_entry_userdate']; ?>"/>  </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-09T02:49:16+00:00Added an answer on June 9, 2026 at 2:49 am

    This is in response to question 1:

    You don’t appear to have matching columns with values in your SQL:

    $query = "INSERT INTO npc_sales_list 
     (npc_item_id // get rid of this
    

    I think you want to get rid of that first column, so you’ll want to do:

    $query = "INSERT INTO npc_sales_list 
     (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_entry_userdate, npc_usertype, npc_points, npc_bonus_points, npc_entry_date)
     VALUES // so on and so forth...
    

    In the SQL insert statement, if you count the number of columns you have and compare with the number of values you have, you’ll notice a mismatch (15 vs 14 which means that the npc_item_id is not necessary, and is probably an auto-incremented unique key anyway).

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

Sidebar

Related Questions

I have a joomla site where users can log in. Once logged in, a
I'm currently developing a Django site in which users can have multiple 'accounts', so
I have a simple site which allows users to upload files (among other things
I have a website which users can sign up to using Facebook Connect (with
I'm setting up Devise such that users can log in and use the site
I have a site and I want to create a log.txt file which includes
i have users who can logon to my site. I don't use the asp.net
I keep having complaints that users are logged in as each other. They can
I have a folder in my site which contains files I don't want users
I have site which uses $(selector).load(path) function in more than 300 pages. Now my

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.