PHP Order Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Eddies
Forum Newbie
Posts: 5
Joined: Mon Nov 23, 2009 6:30 am

PHP Order Form

Post by Eddies »

Greetings people,

I have yet another problem with my current project.

I am creating a point of sale system and I need help with the "Add sale" module of the system and I was hoping for your advice and guide on how to do this.

Basically what I want for this is for users to select the items from the item list in the database in the "newsale.php" page. All the items are select from the database in the "items" table.

newsale.php

Description Category Price Quantity
Item A Cup $1.20 [___3___]
Item B Plate $2.00 [_______]
Item C Bowl $1.50 [___2___]
(Add items)

As of above, User will input the quantity for the items to be purchase from this form and by clicking "Add Items", it will call forth the next page, "processpo.php" which it will identify the id sent and display a similar form as above. The above process is similar to the add to cart function where "processpo.php" is similar to the shopping cart.

At the "processpo.php" page, users will confirm the quantity and details before invoice is submitted to database and print.

Description Category Price Quantity Total
Item A Cup $1.20 [___3___] $3.60
Item C Bowl $1.50 [___2___] $3.00
(Update Items)
(Generate Invoice)

Do I need session for this?

Once again, thanks for the help in advance.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: PHP Order Form

Post by superdezign »

For the initial sending of the data, you need to make use of GET or POST requests. For the persistence of the data across multiple page requests, you will need to use a session.
Eddies
Forum Newbie
Posts: 5
Joined: Mon Nov 23, 2009 6:30 am

Re: PHP Order Form

Post by Eddies »

Hello again,

from all the advices I got so far, I had come out with this but I got this error and I do not know what is the problem. Was wondering if you all could help.

Warning: Invalid argument supplied for foreach() in /home/gwenip/domains/gweniph.com/public_html/ebpos/processpo.php on line 55

Code: Select all

 
<?php
foreach ($_POST['id'] as $itemId => $itemID) {
    $quantity = trim($_POST['quantity'][$itemId]);
    $id = $_POST['id'][$itemId];
    
    if(is_numeric($quantity) == 1 && $quantity >= 1){
    
        $sql = 'SELECT description, category, unit_quantity, uom, van_price FROM items WHERE id = ' . $id;
        $result = $db->query($sql);
        
        while ($row = $result->fetch())
            {
                $description = $row['description'];
                $category = $row['category'];
                $unit_quantity = $row['unit_quantity'];
                $uom = $row['uom'];
                $van_price = $row['van_price'];
            }
            
        $output[] = '<form action="generateinvoice.php" method=post>';  
        $output[] = '<input type="hidden" name="id[' . $id. ']" value="' . $id . '">';
        $output[] = '<table width="920" border="0" align="center" cellpadding="0" cellspacing="0">';
        $output[] = '  <tr>';
        $output[] = '    <td width="920"><table width="920" border="0" cellspacing="0" cellpadding="0">';
        if($trbgcolor != "#FFFFFF"){ $trbgcolor = "#FFFFFF"; }else{ $trbgcolor = "#7EBF41"; }
        $output[] = '      <tr bgcolor="'.$trbgcolor.'">';
        $output[] = '        <td width="45%" class="text"><div align="center">'.$description.'</div></td>';
        $output[] = '        <td width="15%" class="tex"><div align="center"><div align="center">'.$category.'</div></td>';
        $output[] = '        <td width="10%" class="text"><div align="center"><div align="center">'.$unit_quantity.'</div></td>';
        $output[] = '        <td width="10%" class="text"><div align="center"><div align="center">'.$uom.'</div></td>';
        $output[] = '        <td width="10%" class="text"><div align="center"><div align="center">'.number_format($van_price,2).'</div></td>';
        $output[] = '       <td width="10%" class="textheading"><div align="center"><input type=text size="5" name="quantity[' . $row['id'] . ']" value="'.$quantity.'" /></div></td>';
        $output[] = '      </tr>';
        $output[] = '    </table></td>';
        $output[] = '  </tr>';
        $output[] = '</table>';
        
        echo join('',$output);
    }
}
 
    $output2[] = '<table width="920" border="0" align="center" cellpadding="0" cellspacing="0">';
    $output2[] = '  <tr>';
    $output2[] = '    <td><table width="920" border="0" cellspacing="0" cellpadding="0">';
    $output2[] = '      <tr>';
    $output2[] = '        <td width="720"></td>';
    $output2[] = '        <td width="200"><div align="right"><input type="submit" name="addtopo" value="Generate Invoice"></div></td>';
    $output2[] = '      </tr>';
    $output2[] = '    </table></td>';
    $output2[] = '  </tr>';
    $output2[] = '</table>';
    $output2[] = '</form>';
    
    echo join('',$output2);
 
?>
 
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: PHP Order Form

Post by superdezign »

Foreach only accepts traversable objects, like arrays. $_POST['id'] is probably not an array.
Post Reply