Jump to content

Online Quote tool


phatgreenbuds

Recommended Posts

So I am trying to make my life easier at work.  I have this idea that I can automate the sales quote via a simple website.  I have the entire product list in MySQL and I can query for the individual catagories etc etc and get them to display.

 

The display shows the SKU, Description, Price, and a third field to select quantity.  The issue is that once they select a quantity of a paticular line item I need that line item (sku, description, and price fields) to be carried over to the final quote page where the math is done.  Not sure how to key the paticular line item fields off the quantity field.

 

Any ideas greatly appreciated...

 

<?php
$query = "SELECT * FROM tbl_prods WHERE cat = 'fruit'";
$target = mysql_query($query);
confirm_query($target);
while($row = mysql_fetch_assoc($target)) 
 {  
?>
         
<form action="quoter.php"  method="POST">
  <tr>
    <td><input name="sku" type="text" value="<?php echo $row[sku]; ?>" size="20" /></td>
    <td><textarea name="desc" cols="150" rows="2"><?php echo $row[desc]; ?></textarea></td>
    <td><input name="price" type="text" value="<?php echo $row[price]; ?>" size="20" /></td>
    <td><input name="quantity" type="text" value="0" size="3" maxlength="2" /></td>
  </tr>

<?php 
         }
?>

</table> 

<input type="hidden" name="cust" value="<?php echo $cust; ?>"></p>
<input type="hidden" name="reg" value="<?php echo $region; ?>"></p> 
<input type="submit" name="submit" value="Submit"></p> 
</form>

Link to comment
Share on other sites

Well, your first problem is that you are creating several forms on your page, but only having one submit button, and only ending one form with a </form> tag.  Pushing the SUBMIT button might produce some unexpected results.

 

In addition, it looks like you will generally be having multiple items show up on the page, yet each individual items form contains the same field names.  This will make it difficult to extract any reliable data at all on your quotes page.

 

I suggest that the first step you take is to restructure your form so as to eliminate any ambiguity.

 

From the looks of your script, there is no real need for the SKU, Description, and Price fields in your form to begin with (obviously, if there is need for them to be there for other scripts you have, then this won't apply), so my suggestion would be to initiate your form before your while loop, and include your item information inside the loop, but not as form elements.  From there, you could use either an ID number, or even the SKU number as your quantity fields name.

 

<form action="quoter.php"  method="POST">

<?php

$query = "SELECT * FROM tbl_prods WHERE cat = 'fruit'";
$target = mysql_query($query);
confirm_query($target);
while($row = mysql_fetch_assoc($target)) 
 {  
?>

  <tr>
    <td><?php echo $row['sku']; ?></td>
    <td><?php echo $row['desc']; ?></td>
    <td><?php echo $row['price']; ?></td>
    <td><input name="<?php echo $row['sku']; ?>" type="text" value="0" size="3" maxlength="2" /></td>
  </tr>

<?php 
         }
?>

</table> 

<input type="hidden" name="cust" value="<?php echo $cust; ?>"></p>
<input type="hidden" name="reg" value="<?php echo $region; ?>"></p> 
<input type="submit" name="submit" value="Submit"></p> 
</form>

 

And then on quoter.php you can just run a foreach loop through your $_POST superglobal, and discard anything with a value of '0' from consideration (as these will be quantities of 0).  Anything with a value of 1 or greater should be processed with your quote script.

 

quoter.php

<?php

$toquote = array();

foreach ($_POST as $sku => $quantity){
   if ($sku == "cust" || $sku == "reg" || $sku == "submit" || $quantity == 0) {
      //  Don't quote these since these obviously aren't quantity fields
   } else {
      $toquote[$sku] = $quantity;
   }
}

?>

 

The $toquote array would then contain all of the items from the form that needed to be quoted (meaning they had quantities greater than 0), accessible by their SKU number as that items key.

 

Hopefully that helps!

 

EDIT: Fixed a syntax error in the code.  Fast typing FTL.

Link to comment
Share on other sites

ahhh I see. I was having trouble understanding what you did here and thats because I included something that was unrelated. Those two hidden fields are something totally different and not related to this.

 

<?php
$query = "SELECT * FROM tbl_prods WHERE cat = 'fruit'";
$target = mysql_query($query);confirm_query($target);	

while($row = mysql_fetch_assoc($target)) 	 
{  ?>         
<form action="quoter.php"  method="POST">  

<tr>    
<td><input name="sku" type="text" value="<?php echo $row[sku]; ?>" size="20" /></td>    
<td><textarea name="desc" cols="150" rows="2"><?php echo $row[desc]; ?></textarea></td>    
<td><input name="price" type="text" value="<?php echo $row[price]; ?>" size="20" /></td>    
<td><input name="quantity" type="text" value="0" size="3" maxlength="2" /></td>  
</tr>

<?php          
}
?>
</table> 
<input type="submit" name="submit" value="Submit"></p> 
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.