TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 12-06-2009, 08:35 PM   #1 (permalink)
The Visitor
Newcomer 
 
Join Date: Nov 2009
Location: California
Posts: 1
Thanks: 0
lashelles is on a distinguished road
Unhappy Custom Order Form

Hey I've been working about a week on this script but I just can't seem to get it right. I'm trying to build an order form where users are presented with a list (drawn from a mysql relation) of available colors of paint shown in an HTML table. In every <tr> there is one <td> with an text input allowing users to choose their quantity. At the bottom of the form I'd like an add to cart button which stores the items (as well as session_id) into the 'cart' table in my database.

Some of the features I'm hoping for include:

Updating existing quantities if product is already in cart.

If one or more of the posted quantities is higher than the amount in stock, don't add anything to the cart and instead display the page again with an error message detailing which paints exceeded the available stock

If there are no errors display message that items have been added to cart


Some of my main issues include:


I have been doing everything from the same loop and I need to use the loop in areas that are not inside the table.. but as soon as I add another extract() or mysql_fetch_array things go crazy.

I'm not confident at all in what I'm doing



If anybody can help me it would be appreciated.. I've been pulling my hair out over this.


Here is what I've got so far (it's a mess)

PHP Code:
<?php

session_start
();

require_once 
'lib/database.php';

?>

<head>
<link rel="stylesheet" type="text/css" media="screen" href="include/screen.css">
</head>

<form action="<?php echo $_SERVER['PHP_SELF'?>" method="post">
<table id="colorchart" cellpadding="0" cellspacing="0">
<tr style="background:#CCCCCC;">
    <th>No.</th>
    <th>Color</th>
    <th>Series</th>
    <th>Size</th>
    <th>&nbsp</th>
    <th>Price</th>
    <th>Avail.</th>
    <th style="text-align:right; padding-right:25px;">Qty.</th>
</tr>

<?php

$query 
"SELECT mc.color_no, mc.color_name, mc.hex, mc.font, mc.series, pd.size, pd.retail, pd.price, pd.qty, pd.item_no
          FROM product pd
          INNER JOIN mfg_color mc
          ON pd.color_id = mc.color_id"
;
$result mysql_query($query);
$rows mysql_num_rows($result);

$qtycheck 0;
for (
$i 0$i $rows; ++$i) {
    
extract(mysql_fetch_array($result));
    
    
$postqty $_POST["qty$i"];
    if (
$postqty $qty) { 
        
$red 'red';
        
$qtycheck += 1;
        
$stockerror "<br /><span class='stockerror'>*Only <span class='qty'>$qty</span> In Stock</span>";
    }
    elseif (
$postqty 0) {
        
$red '';
        
$stockerror '';
        
$sid session_id();
        
$query2 "SELECT c.item_no
                   FROM cart c
                   WHERE c.item_no = 
$item_no AND c.session_id = $sid";
        
$result2 mysql_query($query2);
        
        if (
mysql_num_rows($result2) == 0) {
            
$query3 "INSERT INTO `lashelles`.`cart` (`cart_id`, `item_no`, `cart_qty`, `session_id`, `date`) 
                       VALUES (NULL, '
$item_no', '$postqty', '$sid', NOW());";
            
mysql_query($query3);
            
        }
        else {
            
$query3 "UPDATE `lashelles`.`cart`
                       SET cart_qty = cart_qty + 
$postqty
                       WHERE item_no = 
$item_no AND session_id = $sid";
            
mysql_query($query3);
        }
        (
mysql_query($query3)) ? $postqty '' $postqty;
    }
    else {
        
$red '';
        
$stockerror '';
    }
        
    
    (
$postqty == '') ? $value $value $postqty;
    
    (
$i == 1) ? $alt "DDDDDD" $alt "FFFFFF";
    (
$font == 'W') ? $font "FFFFFF" $font "000000";
    echo <<<_END
<tr style="background:#$alt;">
    <td>
$color_no</td>
    <td style="background:#
$hex; color:#$font;">$color_name</td>
    <td>
$series</td>
    <td>
$size</td>
    <td class="retail">List: $
$retail</td>
    <td>$
$price</td>
    <td>
$qty</td>
    <td style="text-align:right;"><input type="text" size="3" value="
$value" name="qty$i" style="border:1px solid $red;"/>$stockerror</td>
    
</tr>
_END;
}

?>
<tr><td colspan="8" style="border:0; text-align:right;"><input class="addtocart" type="submit" value="ADD TO CART" name="addtocart" /></td></tr>
</table>

</form>
lashelles is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Keyword Search Form Jako General 1 08-21-2008 07:44 AM
Form to submit to another form patmagpantay General 8 07-21-2008 07:42 AM
email fill in form help? PHP sacred_tinker Absolute Beginners 19 05-28-2008 05:58 AM
Contact Us Form Mohamad Script Giveaway 4 10-03-2007 02:22 PM
Form Processing William Tips & Tricks 8 04-17-2005 03:24 PM


All times are GMT. The time now is 04:13 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design