[56K WARN] $_SESSIONS N00b
Moderator: General Moderators
[56K WARN] $_SESSIONS N00b
Ok I got this new job and my boss has me working on the corporate website which is mostly HTML and PHP. Well I know PHP but with some limitation. I know NOTHING about sessions and the guy who actually did most of the work on here did one hell of a job and no longer works for us. Anyway I have seriously looked at about 100+ sites now trying to find something and my head is about ready to explode this is also about my 4th forum I am trying to get help from. So now I will get to the point and explaine my delema and hopefully some of you PHP wizards can lend a huge helping hand as it is much needed and would be even more appreciated. So with that said, here we go.
The page/form I am designing is based off of one that already exsists on our site now. My plan is to have mine behave EXACTLY like the exsisting one. Only difference with mine is that a customer can enter in a model number and a quantity and hit enter or the update quote button, and after doing so they can build a list of parts for a quote. Now I have on my form a text box called "model" for the customer to enter a product id and I have a text box caled "prod_quantity" where a customer can enter a quantity for the part.
Here is how it all works. We have a MySQL db that all the products and information is stored on. On my form when a "model" number is submited a connection is made to the db and I get a model number in "link" form (this is an href to the parts corisponding image on the server) and I get a "little_desc" which is the short description for that part.
Now if you go here http://www.winsted.com/winstedSQL/famil ... ?name=lcd3 enter in quantities for a few items and hit the update quote button (on bottom of page). Also notice that you can change quantities within the order and outside of the order.Also Now I know that I need a sessions script to handle this which I do not have and also do not understand much. But if I had something to build from I know I could edit it and do it that way and might not be an issue. Here is a rough graphical representation of what I have and what I need.
I have the form part but when a customer types in a model number and a quantity I need it to appear as a list above the form as illustrated.
Based on the information given and any code any of you need me to post if needed, is it possable for anyone to post a sample script that I would beable to fallow and edit and hav working to do what I need it to?
I will submit any code if needed to better help me in my situation.
Thank you all in advance for the help it is greatly appreciated.
The page/form I am designing is based off of one that already exsists on our site now. My plan is to have mine behave EXACTLY like the exsisting one. Only difference with mine is that a customer can enter in a model number and a quantity and hit enter or the update quote button, and after doing so they can build a list of parts for a quote. Now I have on my form a text box called "model" for the customer to enter a product id and I have a text box caled "prod_quantity" where a customer can enter a quantity for the part.
Here is how it all works. We have a MySQL db that all the products and information is stored on. On my form when a "model" number is submited a connection is made to the db and I get a model number in "link" form (this is an href to the parts corisponding image on the server) and I get a "little_desc" which is the short description for that part.
Now if you go here http://www.winsted.com/winstedSQL/famil ... ?name=lcd3 enter in quantities for a few items and hit the update quote button (on bottom of page). Also notice that you can change quantities within the order and outside of the order.Also Now I know that I need a sessions script to handle this which I do not have and also do not understand much. But if I had something to build from I know I could edit it and do it that way and might not be an issue. Here is a rough graphical representation of what I have and what I need.
I have the form part but when a customer types in a model number and a quantity I need it to appear as a list above the form as illustrated.
Based on the information given and any code any of you need me to post if needed, is it possable for anyone to post a sample script that I would beable to fallow and edit and hav working to do what I need it to?
I will submit any code if needed to better help me in my situation.
Thank you all in advance for the help it is greatly appreciated.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Just making sure I understand correctly: you want a form where you enter a product code and quantity and then are able to go to the link you posted and see those products and quantities with the quote there.
Unfortunately in order to help you with your problem we will need you to post code an attempt at what you are trying to do. Sessions are really easy though:
Unfortunately in order to help you with your problem we will need you to post code an attempt at what you are trying to do. Sessions are really easy though:
Code: Select all
session_start();
$_SESSION['foo'] = 'somedata';
// $_SESSION['foo'] is available in all other pages after session_start() nowHere is a nice tutorial that I found while searching for sessions tutorials:
http://www.digiways.com/articles/php/sessauth/
http://www.digiways.com/articles/php/sessauth/
ole: Well ok let me break it down in smaller chunck as to what i need to do and what already works.
1) I have the form created now. I need it to let the customers enter in a model number and a quantity. Keep in mind the customers are here to build a "quote" so the form will need to list more then one item (please refer to my "graphical representation" as to how I want the items to show up)
2) After the customer hits "submit" information is retreived from the db and displayed onto the page. The link stuff I have working now. all the linkwas, is a link form of the model number that can be clicked on to see an image pop up of that item. This can also be seen on the link I posted only that no image pops up.
The script I have is in use on the site now so the code can be and will need to be edited for my need.
Now If I understand this right I think all I need is to be sure the script I have does one of a few things.
1) A new script gets outlined or completed just to handle my page
-or-
2) lightly edit the script to add funtionality so it can handle the things it does now along WITH my form also
so ole here is the script.
Now the two text fields I have on my form are named "prod_quantity" and "model". The script above is unedited by me and infact wasnt even created by me (the guy whos job I have is who did it) I have tried in many ways to edit this and get it to work with my form and no such luck. So please if anyone can get this going it would be a HUGE help and I can get the project done. I have manythings to do to the companies site but this for me is that one HUGE wall I cant seem to get past or through for anything.
Henaro: thank you for the reply I will surely give that site a look and check out the tutorial.
Thank you both again for the help.
1) I have the form created now. I need it to let the customers enter in a model number and a quantity. Keep in mind the customers are here to build a "quote" so the form will need to list more then one item (please refer to my "graphical representation" as to how I want the items to show up)
2) After the customer hits "submit" information is retreived from the db and displayed onto the page. The link stuff I have working now. all the linkwas, is a link form of the model number that can be clicked on to see an image pop up of that item. This can also be seen on the link I posted only that no image pops up.
The script I have is in use on the site now so the code can be and will need to be edited for my need.
Now If I understand this right I think all I need is to be sure the script I have does one of a few things.
1) A new script gets outlined or completed just to handle my page
-or-
2) lightly edit the script to add funtionality so it can handle the things it does now along WITH my form also
so ole here is the script.
Code: Select all
<?php
// Don't want links with ampersands in them (XHTML).
ini_set ("arg_separator","&");
// Directory where common include files are stored
define("PHPINCDIR","../../phpinc/");
// This holds the classes used to build the page (Product, Family, Label and System)
require_once(PHPINCDIR.'class_page.php');
/* Set up PHP/mySQL stuff */
require_once(PHPINCDIR.'db.php');
// Functions for printing html
require_once(PHPINCDIR.'html_family.php');
// Misc Quote Functions
require_once(PHPINCDIR."quotefunctions.php");
// Common Page Generation Functions
require_once(PHPINCDIR."html_common.php");
/* End Setup PHP/mySQL stuff */
// Debug
//error_reporting(E_ALL);
//list($susec, $ssec) = explode(" ", microtime());
// Create Session if we are not a known search engine bot
// Avoid passing bots session ids
if (!stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'Googlebot') && !stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'YahooSeeker') && !stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'msnbot') && !stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'Yahoo-VerticalCrawler') && !stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'Scooter') && !stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'slurp')) {
session_cache_limiter('nocache');
//Cart stuff is stored in session variables, sessions used in section_builder code
session_start();
}
/* Check for GET data */
if(!isset($_GET["name"]))
{
// Name is not passed in, create error page
message_page("Error!<br><br>No page name provided.", "Error");
return;
}
/* End GET data check*/
/* Open Winsted DB */
$db_connect = new db();
/* End DB open */
if(!isset($_GET['page'])) {
// No Page number passed in so on page 1
$pagenum = 1;
}
else {
$pagenum = intval($_GET['page']);
if($pagenum < 1) {
$pagenum = 1;
}
}
/* Create page, if doesn't exist, print error */
$current_page = new prod_family($_GET['name']);
$etype = $current_page->get_error();
if($etype !== false) {
// 404 redirect on error
if($etype === 2) {
header("HTTP/1.0 404 Not Found");
message_page($current_page->get_error_msg(), "Error");
return;
}
else {
message_page($current_page->get_error_msg(), "Error");
return;
}
}
// Create links for clearing cart, previous page
$_SESSION['prev_page'] = "family_sess.php?name=".$current_page->get_familyID();
if(isset($_GET["page"])) {
$_SESSION['prev_page'] .= '&page='.$_GET["page"];
}
// Clear Cart link
$clearcart = $_SESSION['prev_page'];
if(isset($_GET["action"])) {
$_SESSION['prev_page'] .= '&action=update_product';
$clearcart .= '&action=clear';
}
// Update session details here. We need to do this stuff above any html writes, going to use header
// to redirect to page we came from.
// Process cart
if(isset($_GET['action'])) {
// Replace ifs with switch
switch($_GET['action']) {
case "update_product":
if(isset($_POST)) {
// Figure out which form was updated. Either the one at bottom of page or top.
// Each has different prefix for array name
if(isset($_POST['Change_x']) || isset($_POST['getchange_x'])) {
if(isset($_POST['cart_quantity']) && is_array($_POST['cart_quantity'])) {
$numrows = sizeof($_POST['cart_quantity']);
}
else {
$numrows = 0;
}
$cart_array = 'cart';
}
else {
if(isset($_POST['prod_quantity']) && is_array($_POST['prod_quantity'])) {
$numrows = sizeof($_POST['prod_quantity']);
}
else {
$numrows = 0;
}
$cart_array = 'prod';
}
$cart_id = $cart_array.'_id';
$cart_quan = $cart_array.'_quantity';
// If cart is not in session add it
if(!isset($_SESSION['prod_quantity'])) {
$_SESSION['prod_quantity'] = array();
}
// Process POST vatiables, look for dupes.
$cart_ids = array();
for($i=0;$i < $numrows;$i++) {
// Scrub post values
if(isset($_POST[$cart_id][$i])) {
$temp_id = intval($_POST[$cart_id][$i]);
if(isset($_POST[$cart_quan][$i])) {
$temp_quan = intval($_POST[$cart_quan][$i]);
if(isset($_SESSION['prod_quantity'][$temp_id])) {
if($_SESSION['prod_quantity'][$temp_id] != $temp_quan) {
if(isset($cart_ids[$temp_id])) {
// Dupe detected, add quantity?
$cart_ids[$temp_id] += $temp_quan;
}
else {
$cart_ids[$temp_id] = $temp_quan;
}
}
}
else {
if(isset($cart_ids[$temp_id])) {
// Dupe detected, add quantity?
$cart_ids[$temp_id] += $temp_quan;
}
else {
$cart_ids[$temp_id] = $temp_quan;
}
}
}
}
}
$numrows = sizeof($cart_ids);
foreach($cart_ids as $product_id => $quantity) {
if(isset($_SESSION['prod_quantity'][$product_id])) {
// Change quantity to model quantity
// If zero, remove from array
if($_SESSION['prod_quantity'][$product_id] != $quantity) {
if($quantity > 0) {
$_SESSION['prod_quantity'][$product_id] = $quantity;
}
// If quantity = 0 remove from array
else {
unset($_SESSION['prod_quantity'][$product_id]);
}
}
}
else {
// New model, add to end of array if it has quantity
if($quantity > 0) {
// Check legality of model number, avoid injection attack
$_SESSION['prod_quantity'][$product_id] = $quantity;
}
}
}
unset($cart_ids);
// Redirect to quote page if we are getting quote, end script
// We are checking which button was used to submit
if(isset($_POST['getchange_x'])) {
session_write_close();
// For 1.0 http clients send out default 302 status
if(0 == strcmp($_SERVER['SERVER_PROTOCOL'],'HTTP/1.1')) {
header("HTTP/1.1 303 See Other");
}
header('Location: http://'.$_SERVER['HTTP_HOST'].'/winstedSQL/quote_sess.php'); /* Redirect browser */
exit;
}
unset($cart_ids);
}
break;
// Nuke cart
case "clear":
unset($_SESSION['prod_quantity']);
break;
}
}
else {
// No action added yet so add one
$_SESSION['prev_page'] .= "&action=update_product";
$clearcart .= "&action=clear";
}
// Target
$_SESSION['prev_page'] .= "#quote";
$clearcart .= "#quote";
// Create cart
if(!isset($_SESSION['prod_quantity'])) {
$_SESSION['prod_quantity'] = array();
}
// Now we build the page, this uses cart variables for quantities
$retval = $current_page->build_page($pagenum);
if($retval === false) {
message_page($current_page->get_error_msg(), "Error");
return;
}
$cart = array();
$i = 0;
// Fill out cart
foreach ($_SESSION['prod_quantity'] as $id => $quantity) {
// Get information for prod
$query = 'SELECT model,little_desc FROM product WHERE id = '.intval($id);
$prod = mysql_query($query) or die("Query failed");
$desc = mysql_fetch_array($prod, MYSQL_ASSOC);
$cart[$i][0] = intval($id);
$cart[$i][1] = intval($quantity);
$cart[$i][2] = $desc['model'];
$cart[$i][3] = $desc['little_desc'];
$i++;
}
// Print html for page
/* Gzip, caching and search engine robot stuff */
// Gzip up stuff, MSN doesn't seem to handle so don't
if(!stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'msnbot')) {
ob_start("ob_gzhandler");
}
print_html($current_page, $cart, $_SESSION['prev_page'], $clearcart);
// End Script
// Flush cache, MSN isn't so smart it seems
if(!stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'] ,'msnbot')) {
ob_end_flush();
}
// DEBUG
// list($fusec, $fsec) = explode(" ", microtime());
// $ttime = (float)(((float)$fsec + (float)$fusec)) - (float)(((float)$ssec + (float)$susec));
// system('echo "Total time: '.$ttime.'" >> /tmp/results.txt');
?>Henaro: thank you for the reply I will surely give that site a look and check out the tutorial.
Thank you both again for the help.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Sorry I really can't motivate myself to look through all that code and write you the solution, I'm not being paid you know. I am willing to answer questions, help you fix personal attempts to do something.
In short -- try it yourself and come back with specific queries should you have any problems and we'll point you in the right direction.
In short -- try it yourself and come back with specific queries should you have any problems and we'll point you in the right direction.
Unfortunately posting somebody else's code does not satisfy this.I wrote:Unfortunately in order to help you with your problem we will need you to post code an attempt at what you are trying to do
Ok I can uderstand that. Hell its a project for me at my job and I am being paied and I still hate looking through all the code
Did my break down explination as to what I want to do help at all or give you any ideas as to what Im trying to do?
To make it realy simple and to clear any clouds that might exsist in this, I believe all I need is a sessions script to handle my form and to handle functionality of a few buttons "clear", "update quote" , "get quote" and "change quote".
I have attempted to write something, i dont want to make all of this sound like I want someone to write a 400 line sessions script for me or anything. But its just when I look at some of the code I get as far as putting in session_start()
$_SESSION ['prod_quantity']
$_SESSION ['model']
Then I go blank and have NO idea what to do.lol
Maybe to make it simple Ill just make a totaly seperate script and not worry about doing anything with the posted one I just put up. But if I could get just a basic (but easy for me to understand) outline script that I could "taylor" or edit to my form that would even be a HUGE help and step in the right direction. Like I said though if thats at all possable. I dont know alot about this so I dont know if its something you can just wip up in a few minutes or not but if you can it would be much appreciated. That way I can edit what I need to and still end up doing the other things that need to be done myself to.
Thank you for your help and responses ole.
Did my break down explination as to what I want to do help at all or give you any ideas as to what Im trying to do?
To make it realy simple and to clear any clouds that might exsist in this, I believe all I need is a sessions script to handle my form and to handle functionality of a few buttons "clear", "update quote" , "get quote" and "change quote".
I have attempted to write something, i dont want to make all of this sound like I want someone to write a 400 line sessions script for me or anything. But its just when I look at some of the code I get as far as putting in session_start()
$_SESSION ['prod_quantity']
$_SESSION ['model']
Then I go blank and have NO idea what to do.lol
Maybe to make it simple Ill just make a totaly seperate script and not worry about doing anything with the posted one I just put up. But if I could get just a basic (but easy for me to understand) outline script that I could "taylor" or edit to my form that would even be a HUGE help and step in the right direction. Like I said though if thats at all possable. I dont know alot about this so I dont know if its something you can just wip up in a few minutes or not but if you can it would be much appreciated. That way I can edit what I need to and still end up doing the other things that need to be done myself to.
Thank you for your help and responses ole.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
OK crazy8, you have a good attitude.
A littleDid my break down explination as to what I want to do help at all or give you any ideas as to what Im trying to do?
could you show me the form?I believe all I need is a sessions script to handle my form and to handle functionality of a few buttons "clear", "update quote" , "get quote" and "change quote".
OK this is a common problem. How about writing down a sequential list of instructions that you would like to happen and I can help you translate it to PHP.Then I go blank and have NO idea what to do.lol
Not a bad idea, generally if something is working and you need to add to it you should avoid modifying what's already working and write something new.Maybe to make it simple Ill just make a totaly seperate script and not worry about doing anything with the posted one I just put up.
Ok ole here is the code for the form. This isnt th whole html, just the code for the form.The first line you can kind of ignore. I know it needs to be used to point at the "sessions" script in my case, doesnt it? Anyway I have been doing all sorts of stuff tot hat first line just so you know.
Simple: To have my form behave EXACTLY like the existing one on the site.Refer to the link in my first post.
More complex:
1) Page containing the form loads.(At this point the actual form cosists of a quantity and model text input boxes along with one button "update quote" which will submit the entered information.)
2) Customer enters in a model number and a quantity and hits "update quote"
3) The quantity entered along with model and description get posted as a list right above the form to start building a list of items to be quoted by us when the order is complete.
**model and description even though typed are also grabed from the db then displayed onto the page just above the form as a list**
4) When customer hits "update quote" I also would like to have 3 other buttons apear onto the form, "clear quote", "change quote", "get quote". "clear quote" clears the cart/list, "change quote" can be hit when a customer changes any quantity of an item in the list they have formed. For this I need the quantities of all the items in the list to apear in text input boxes so the quantities can be changed by the customer. Lastly "get quote" simply will then be hit and customer will be directed to a page which is already on the site to, and there they will fill out order/personal information.
5)Now what happens here in this step is also something that already happens on the site I just havent figured out where in all this it happens. Once the page with the personal/order information is submited the order/quote the customer built gets emailed to us the server looks at all the items entered and does the math. The customer gets quote in email if they are located inside the US. If they are outside then the quote gets directed to Winsted in England. But im certain this is all stuff you dont need to worry about.
I hope I did a good job explaining all that. I know sometimes explaining technical things just confuses more then it may realy be.But again if you have any questions about the above explination and trying to figure out how I would like it all to work just goto the link I posted in my first post and actually play with what we have already and that way you get a first hand idea what I need since I realy want to have mine work exactly like it.
Thank you so much for your patiants and your help, it is greatly appreciated.
Code: Select all
<form name="cart_quantity" action="famtest.php" method="POST" style="display:inline; margin:0px;" autocomplete = "off">
<div class="bttns"><input type="image" src="i/update_quote.gif" border="0" alt="Update Totals"></div>
<a name="quote"></a><div class="h2brdr"><h2>Current Quote</h2></div>
<table width="600" height="20" border="0" align="center" cellspacing="0">
<tr><td align="center" width="107" class="plinky"><strong>Quantity:</strong></td>
<td class="plinky" align="center" width="85"><input name="prod_quantity" value="0" size="2" maxlength="4" class="quanw" type="text">
</td>
<td width="402" align="left" class="plinky"><strong>Enter Model Number:</strong>
<input name="model" style="width: 50px;" size="20" maxlength="20" class="quanw" value="" type="text">
</td>
</tr></table>
</form>If I understand what you are saying here is the instruction son what I would like to happen.OK this is a common problem. How about writing down a sequential list of instructions that you would like to happen and I can help you translate it to PHP.
Simple: To have my form behave EXACTLY like the existing one on the site.Refer to the link in my first post.
More complex:
1) Page containing the form loads.(At this point the actual form cosists of a quantity and model text input boxes along with one button "update quote" which will submit the entered information.)
2) Customer enters in a model number and a quantity and hits "update quote"
3) The quantity entered along with model and description get posted as a list right above the form to start building a list of items to be quoted by us when the order is complete.
**model and description even though typed are also grabed from the db then displayed onto the page just above the form as a list**
4) When customer hits "update quote" I also would like to have 3 other buttons apear onto the form, "clear quote", "change quote", "get quote". "clear quote" clears the cart/list, "change quote" can be hit when a customer changes any quantity of an item in the list they have formed. For this I need the quantities of all the items in the list to apear in text input boxes so the quantities can be changed by the customer. Lastly "get quote" simply will then be hit and customer will be directed to a page which is already on the site to, and there they will fill out order/personal information.
5)Now what happens here in this step is also something that already happens on the site I just havent figured out where in all this it happens. Once the page with the personal/order information is submited the order/quote the customer built gets emailed to us the server looks at all the items entered and does the math. The customer gets quote in email if they are located inside the US. If they are outside then the quote gets directed to Winsted in England. But im certain this is all stuff you dont need to worry about.
I hope I did a good job explaining all that. I know sometimes explaining technical things just confuses more then it may realy be.But again if you have any questions about the above explination and trying to figure out how I would like it all to work just goto the link I posted in my first post and actually play with what we have already and that way you get a first hand idea what I need since I realy want to have mine work exactly like it.
Thank you so much for your patiants and your help, it is greatly appreciated.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
I'm obviously in this for the long haul now 
What I meant by "a sequential list of instructions" was pseudocode. On this Wikipedia article about pseudocode there is a great example (in PHP no less) of what pseudocode should look like and how it is equivalent to real code.
What you have provided is yet another description of what you want done. It is actually your best description yet and I now understand what you want done fully but it isn't getting you, personally, much closer to what you want unless you decide to have a programmer write it for you.
Here's some possible pseudocode for what you wrote -- you can tell me if it is right its also obviously no where near complete.
What I meant by "a sequential list of instructions" was pseudocode. On this Wikipedia article about pseudocode there is a great example (in PHP no less) of what pseudocode should look like and how it is equivalent to real code.
What you have provided is yet another description of what you want done. It is actually your best description yet and I now understand what you want done fully but it isn't getting you, personally, much closer to what you want unless you decide to have a programmer write it for you.
Here's some possible pseudocode for what you wrote -- you can tell me if it is right its also obviously no where near complete.
Code: Select all
if user has submitted data {
if the button pressed was "update quote" {
// stuff
} else if the button pressed was "clear quote" {
wipe all stored session data
}
} else {
}
render form by {
get products from database
for each product queried {
display necessary details such as title and description
create a text field for quantity input
create a text field for model number input
if quantity data for this product is present {
populate quantity text field with quantity data
}
if model number data for this product is present {
populate quantity text field with quantity data
}
}
create a button labelled "update quote" that submits the form
create a button labelled "clear quote" that submits the form
}sorry about the confusion. Based off of what you have here are a few small edits to what I think I need.
The form will start with only one button, that being the "update quote" then after that is pressed the other 3 will show then, "clear quote", "change quote", and "get quote"
Also as part pf the script I made to call the DB this is currently what I use to grab the model and description from the db.
I think I edited that all right. Sorry about the confusion and difficulty.
The form will start with only one button, that being the "update quote" then after that is pressed the other 3 will show then, "clear quote", "change quote", and "get quote"
Code: Select all
if user has submitted data {
if the button pressed was "update quote" {
// stuff
} else if the button pressed was "clear quote" {<---based on whats above Im not sure if I need this or not
wipe all stored session data
}
} else {
}
render form by {
get products from database
for each product queried {
display necessary details such as model number and description
create a text field for quantity input<----already exists on original form but yes will be created to make amounts for each product already added to the cart/list so customer can change quantities if needed. If customer did change a quantity, this is where "change quote" button comes into play.
create a text field for model number input<----already exists on form only need it for the form itself
if quantity data for this product is present {
populate quantity text field with quantity data (only if model number exists in db)<--if possable?
}
if model number data for this product is present {
post next to/with quantity data for this item
}
}
create a button labelled "update quote" that submits the form
create a button labelled "clear quote" that clears the form
create a button labelled "get quote" that will redirect customer to personal info/order info page
}Code: Select all
echo '<a href="ptest.php?n='.$row['id'].'">'.$row['model'].'</a> '.$row['little_desc'];- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: $_SESSIONS N00b
This is not necessarily the case. What is going to be happening to the data after it is updated? This could be a simple matter of capturing $_POST values and feeding them back into the form. What is your business logic and what do you want to do with the data in the form?crazy8 wrote:Also Now I know that I need a sessions script to handle this ...
Well what I need to my understanding is something that is the equivelance of a cart. A customer will keep typing model numbers and quantities for each item untill he/she has a complete order they would like a quote on.
The "updated part" is simply the "update quote" button I assume is what your refering to. If thats the case, when "update quote" is pressed or enter key is pressed the info they entered (model number and quantity) does get POSTed yes quantity is just echoed but my form is also using a script to retreive the model number and a little description of the item which gets posted to the form page.
Once all the data (list of products and quantities) is in the form that the customer has "built" if you will, that "list" will be submited and a "quote" is generated by our system based on the items in the list. To explaine we have prices for everything in our DB so the system matches the item numbers with whats in our db and therefore generates the quote and emails it to the customer.
The "updated part" is simply the "update quote" button I assume is what your refering to. If thats the case, when "update quote" is pressed or enter key is pressed the info they entered (model number and quantity) does get POSTed yes quantity is just echoed but my form is also using a script to retreive the model number and a little description of the item which gets posted to the form page.
Once all the data (list of products and quantities) is in the form that the customer has "built" if you will, that "list" will be submited and a "quote" is generated by our system based on the items in the list. To explaine we have prices for everything in our DB so the system matches the item numbers with whats in our db and therefore generates the quote and emails it to the customer.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
My thoughts...
Build your form with defaults values set to 0. When the submit button is pressed, process the quote based on what is in the form (either 0 or what the user entered). If the 'Update Quote' button is pressed, shoe the form and default the values of the form to what was in the form before the update button was pressed. Since you are not selling anything from this (at least you haven't stated that you are) and it appears that this form serves a single purpose which is to allow the users to request a dynamic quote, it seems that session'ing this might be too much.
This is just a simplified example of what I am talking about. THIS IS NOT WORKING CODE!
Build your form with defaults values set to 0. When the submit button is pressed, process the quote based on what is in the form (either 0 or what the user entered). If the 'Update Quote' button is pressed, shoe the form and default the values of the form to what was in the form before the update button was pressed. Since you are not selling anything from this (at least you haven't stated that you are) and it appears that this form serves a single purpose which is to allow the users to request a dynamic quote, it seems that session'ing this might be too much.
This is just a simplified example of what I am talking about. THIS IS NOT WORKING CODE!
Code: Select all
<?php
// This tells us to show the form or not
$show_form = true;
if (isset($_POST['update_quote']))
{
// The user wants to update their quote
// Handle the post vars
$item1 = $_POST['item1'];
$item2 = $_POST['item2'];
}
elseif (isset($_POST['submit_request']))
{
// the user is finished and wants a complete quote
// Handle the quote making AND DO NOT SHOW THE FORM
$show_form = false;
}
else
{
// Set default values that will feed the form
$item1 = 0; // This simulates a field name that feeds _POST
$item2 = 0; // This simulates a field name that feeds _POST
}
// Do we need to show the form?
if ($show_form):
?>
<form method="post" action="<?php echo basename($_SERVER['SCRIPT_FILENAME']); ?>" id="quote-form">
<p>Item 1 Count:</p>
<p><input type="text" name="item1" value="<?php echo $item1; ?>" /></p>
<p>Item 2 Count:</p>
<p><input type="text" name="item2" value="<?php echo $item2; ?>" /></p>
<input type="submit" name="update_quote" value="Update this quote" />
<input type="submit" name="submit_request" value="Submit quote request" />
</form>
<?php endif; ?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Well I must be blessed then. My boss knows I copy the files, save them to my thumb drive and even have a CD burned, he is also aware im pulling "resources" and getting help on this project so he is aware of what I am doing and is ok with it. But yea I know alot of big companies so much as see a single line of code from there site even leave the server or even get a wired fishy gut feeling about an employee they have a corinary, call the lawyers and have frequent heart attacks. So yea I know what your saying lucky for me I havent had to be in those shoes.lol