Verify model with DB
Posted: Wed Jan 24, 2007 4:06 pm
Ok so here is the deal. I have this small script below which grabs certain info off the DB and gets displayed into a table/form on a page. Now on the page a customer types in a model number and a qauntity and then after "enter" is hit and form gets submitted information of that product and its quantity get displayed onto the page. Well I do know that over time products will come and products will go and changes will have to be made to the DB to account for these changes. So one thing I would like to do but not sure how to do it, is to add some sort of model number verification. here is a workflow idea.
- Customer types in a model number (along with a quantity of course)
- Customer submits the form
- OOPS there is an error
- A new "small" window pops up and tells the customer "Were sorry the Item you have entered is no longer available."
So how would this be coded? because to be honest Im not sure where to even begin on how to do this with PHP.
Here is the script I have created upto now.
- Customer types in a model number (along with a quantity of course)
- Customer submits the form
- OOPS there is an error
- A new "small" window pops up and tells the customer "Were sorry the Item you have entered is no longer available."
So how would this be coded? because to be honest Im not sure where to even begin on how to do this with PHP.
Here is the script I have created upto now.
Code: Select all
<?php
define("PHPINCDIR","../../phpinc/");
include ('ez_db.php');
require_once(PHPINCDIR.'ez_html_family.php');
require_once(PHPINCDIR.'ez_class_page.php');
require_once(PHPINCDIR."quotefunctions.php");
if (!empty($_POST['prod_quantity']) AND !empty($_POST['model'])){
$_SESSION['prod_quantity'][$_POST['model']] = $_POST['prod_quantity'];
} elseif (!empty($_POST['cart_quantity'])){
// update qty in cart session after submit
for ($i=0; $i<count($_SESSION['prod_quantity']); $i++){
if ($_POST['cart_quantity'][$i] >= 1){
$_SESSION['prod_quantity'][$_POST['cart_id'][$i]] = $_POST['cart_quantity'][$i];
} else {
$_SESSION['prod_quantity'][$_POST['cart_id'][$i]] = '';
unset($_SESSION['prod_quantity'][$_POST['cart_id'][$i]]);
}
}
}
if (is_array($_SESSION['prod_quantity'])){
foreach ($_SESSION['prod_quantity'] AS $prod=>$qty){
$sql = mysql_query("SELECT * FROM product WHERE model='$prod'");
$row = mysql_fetch_array($sql);
echo '<a href="p.php?n='.$row['id'].'">'.$row['model'].'</a> '.$row['little_desc']."\n";
echo "<input type=\"text\" name=\"cart_quantity[]\" value=\"$qty\" size=\"2\" maxlength=\"4\" style=\"width: 40px\" class=\"quanw\">
<input type=\"hidden\" name=\"cart_id[]\" value=\"$prod\"><br />";
}
}
?>