Jump to content

Serious help with php form and files


crazy8

Recommended Posts

Ok I know this is all going to be alot but I am having so many issues im not sure where to start or even where to begin considering im still new to PHP. Im at the end of my wits here. This code I am writing is job related and the guy who wrote all of this before me did a hell of a job (in a good way) only issue with that is its just to much. to many scripts that all tie in together and way to much code. I have been asked to create a new page for our corporate website, all of the exisiting code is good but over kill for what I am doing.So I will start from the top here. I have created a form with two input boxes, one for a model number ( like a product ID realy ) and a quantity. Now this form allows our customers to build a list of items they would like for their project and build a quote. Once they hit the "Update Quote" button (Kind of like an add to cart) a connection is made to the database and a model number (in link form which is linked to an image), short description of that item are retrieved and the quantity they had entered gets echoed next to that item. If you would like to see a graphical representation of this let me know and Ill post some images for you. Ok so now with the code and my issues.

I have created a sessions script that is inbeded into my form that works great but there is a few issues. First off I will mention that with the "original" sessions script would not work with my form for whatever reasons and the new one is much shorter to. Now with the original sessions script there were an additional 5 scripts that were part of it via "require_once". I can not for the life of me get any of these scripts to work with my new sessions script. There is one that atleast to me is more important to me then the other 4 and that is because it has everything to do with how the data gets displayed along with 2 buttons that pop up after the first initial submition of the form and a few other things. Now If I new how to code this stuff in "short hand" so to speak so I could just have a few lines of code that I could put into my form to pull all of this off I would. I have tried that in many different ways and for the life of me nothing seems to work. Im not one to come of as a person to beg, matter a fact I never do but this is my absolute last hope and time for this project to be done is neering no mater where I am at. Id rather have it complete and in FULL working condition when the deadline is here. I need as much help as I can possably get. So I will post up code I got and do some explaining as I post it. Sorry to drage this on like this. Here we go...


This here is my sessions script. Keep in mind this is embeded into my form/page. Also it seems the only way I have been able to get desired results is using the 2 "echo's" I have in this, is there a better way to get the same desired results and not echo?
[code]<?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");
require_once(PHPINCDIR."html_common.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 />";
    }
}
?>[/code]

Now the original script was link to another one called "html_family.php" which is the script I want to work more then anything. So I need to do one of two things, ether get it to work or strip code from it that I need (my buttons and their functionality, how the data gets displayed, etc) and some how get that to work somehow. Here is a small sample of that script. The actual script is 400 lines long and this is the "nice" looking part verses the rest of it.
[code]for($i = 0; $i < $numrows; $i++)  {


// Don't want to print out prod stuff unless we are sure we have component
if($firstrow == 1)  {
$page_out .= '<td align="center" class="plinky"><strong>Products:</strong></td>';
$firstrow = 0;
}
else {
$page_out .= '<tr><td class="plinky"><img src="i/t.gif" alt="" height="1" width="90"></td>'; // This column will hold the header for component, accessory
}
$page_out .= '<td align="center" class="plinky"><a href="ez_p.php?n='.$cart[$i][0].'" target="_blank" onclick="javascript:op(\'ez_p.php?n='.$cart[$i][0].'\'); return false">'.$cart[$i][2].'</a></td>';
$page_out .= '<td align="left" class="plinky">'.$cart[$i][3].'</td>';
$page_out .= '<td align="center" class="nets"><input type="text" name="cart_quantity[]" value="'.$cart[$i][1].'" style="width: 40px;" size="5" maxlength="5" class="quanw"><input type="hidden" name="cart_id[]" value="'.$cart[$i][0].'"></td></tr>';
$page_out .= '<td align="center" width="107" class="plinky"><strong>Quantity:</strong></td>';
    $page_out .= '<td class="plinky" align="center" width="85"><input name="prod_quantity" style="width: 40px;" value="" size="5" maxlength="5" class="quanw" type="text"></td>';
    $page_out .= '<td width="402" align="left" class="plinky"><strong>Enter Model Number:</strong>';
$page_out .= '<input name="model" style="width: 50px;" size="20" maxlength="20" class="quanw" value="" type="text"></td>';


}[/code]
Here is the buttons bit.[code] if($numrows != 0)  {
// We found $clearcart at the top
$page_out .= '<div class="bttns">';
$page_out .= '<a href="'.$clearcart.'"><img src="i/clear_quote.gif" border="0" alt="Clear Quote" class="multi"></a><input type="image" src="i/update_quote.gif" border="0" alt="Update Totals"><input type="image" src="i/get_quote.gif" border="0" alt="Get Quote" name="getquote">';
$page_out .= '</div>'."\n";
} [/code] Ill start you all off with that. One added issue im having is that my css files which are mentioned (they are imported) on the same script as my sessions and my regualr HTML are for the page. But it seems that atleast for the most part the work for th page itself but there are some vertical grey lines I have set up that shoul;d show up inside my "quote list" to better organise it and such.

Anyway im drawing this out horably long Im sure I will shut up now and give any/all of you much thanks for any help that you can assist. If anything is needed from me that isnt posted now that would better help me feel free to ask. Thank you all so much again.
Link to comment
https://forums.phpfreaks.com/topic/35868-serious-help-with-php-form-and-files/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.