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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:02:39+00:00 2026-05-24T16:02:39+00:00

Hey there. When I use the following function: function ship_order($id, $order_items, $products) { $connection

  • 0

Hey there. When I use the following function:

function ship_order($id, $order_items, $products)
{
    $connection = mysql_open();

    foreach ($order_items as $order_item)
    {
        foreach ($products as $product)
        {
            if ($order_item['product_id'] == $product['id'])
            {
                if ($order_item['quantity'] > $product['stock'])
                {
                    return false;
                }
            }
        }
    }

    $query = "update SEOrders " .
         "set status='Shipped' " .
         "where id = $id";

    $result = mysql_query($query, $connection) or show_error();

    foreach ($order_items as $order_item)
    {
        foreach ($products as $product)
        {
            if ($order_item['product_id'] == $product['id'])
            {
                $new_stock = $product['stock'] - $order_item['quantity'];
                $sold_stock = $product['sold_stock'] + $order_item['quantity'];

                $query = "update SEProducts " .
                         "set sold_stock= '$sold_stock', stock='$new_stock' " .
                         "where id = $id";

                $result = mysql_query($query, $connection) or show_error();
            }
        }
    }

    mysql_close($connection) or show_error();
    return true;
}

I will occassionally get an error which looks like this:

Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 176 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/home/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Notice: Undefined index: product_id in /net/export/home/public_html/wp/SE/includes/defs.php on line 196 Warning: Cannot modify header information - headers already sent by (output started at /net/export/home/public_html/wp/SE/includes/defs.php:196) in /net/export/home/public_html/wp/SE/ship_order_action.php on line 21

BUT ONLY EVERY NOW AND THEN. I have no idea why it only happens on occasion.

Also, the mysql_open() function is defined here:

function mysql_open() 
{
  $connection = @ mysql_connect(HOST, USER, PASSWORD)
      or die("Could not connect");
  mysql_select_db(DATABASE, $connection)
      or show_error();
  return $connection;
}

Where HOST, USEr… etc are defined in a separate file.

The $id that is passed in is straight from the page and I’ve checked it. The $order_items is pass in through:

function get_order_items($id)
{
    $connection = mysql_open();
    $query = "select oi.order_id, p.name, oi.quantity, p.stock " .
             "from SEOrder_items as oi join SEProducts p on oi.product_id = p.id " .
             "where oi.order_id = $id";
    $result = mysql_query($query, $connection) or show_error();
    mysql_close($connection) or show_error();

    $order_items = array();
    while ($order_item = mysql_fetch_array($result)) 
    {
        $order_items[] = $order_item;
    }

    return $order_items;
}

and the $products are passed in through:

function get_products()
{
    $connection = mysql_open();
    $query = "SELECT * FROM SEProducts";
    $query .= " order by name asc";
    $result = mysql_query($query, $connection) or show_error();

    $products = array();
    while ($product = mysql_fetch_array($result)) 
    {
        $products[] = $product;
    }

    mysql_close($connection) or show_error();

    return $products;
}

In case it’s relevant, the database looks like this:

create table if not exists SEOrders
(
    id int not null auto_increment primary key,
    name varchar(20) not null,
    address varchar(30) not null,
    status varchar(10) not null,
    dateShipped timestamp
)ENGINE=INNODB;

create table if not exists SEProducts
(
    id int not null auto_increment primary key,
    price double not null,
    name varchar(30) not null,
    stock int not null,
    original_stock int not null,
    sold_stock int not null
)ENGINE=INNODB;

create table if not exists SEOrder_items
(
    id int not null auto_increment primary key,
    order_id int not null,
    foreign key (order_id) references SEOrders(id),
    product_id int not null,
    foreign key (product_id) references SEProducts(id),
    quantity int not null
)ENGINE=INNODB;

Basically what I’m trying to do is subtract the quantity from the current stock as well as adding the quantity to the sold stock. However this isn’t quite working and every now and then I’ll get the error described above. But the strange thing is that I’ll call the function several times with no problem.

Thanks in advance,
JheeBz

  • 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-05-24T16:02:40+00:00Added an answer on May 24, 2026 at 4:02 pm

    Just replace this function, this might work.

    function get_order_items($id)
    {
        $connection = mysql_open();
        $query = "select p.id, oi.order_id, p.name, oi.quantity, p.stock, oi.product_id " .
                 "from SEOrder_items as oi join SEProducts p on oi.product_id = p.id " .
                 "where oi.order_id = $id";
        $result = mysql_query($query, $connection) or show_error();
        mysql_close($connection) or show_error();
    
        $order_items = array();
        while ($order_item = mysql_fetch_array($result)) 
        {
            $order_items[] = $order_item;
        }
    
        return $order_items;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have use following code to display category and there product on click patent
Hey there, I keep hearing over and over again that I should ALWAYS use
hey there - I'm trying to use asp.net mvc for some things as usual,
Hey there, I have read the few posts here on when/how to use the
Hey there. I have to use the Google Chrome Frame to support certain HTML5-features
Hey there, I have 20 divs floated left with different height. I use this
Hey there, I've got a block of HTML that I'm going to be using
Hey there, I am trying to get my signout button to work. This is
Hey there, I'm sort of new to Objective-C, and well, programming in general. I
Hey there, I'm a designer thats really new to programming with xcode or Objective-C

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.