Results 1 to 3 of 3
  1. #1

    php forms and arrays reading from text files

    please be forewarned, this msg might be a little lengthy:

    I am creating 1 form per item consisting of electronic chips. There is one item per series and I have about 9 series of chips. Each series has a different number of chips within the series.

    I, so far, have coded the items to be read off of a text file because that is how the customer wanted to update the inventory. I then display the items in the form and everything gets put on the web page.

    I have three buttons on the form:

    Add to Cart = name=$cart
    Reset Item = name=$rSubmit
    Check Out = name=$bSubmit.

    for value comparison purposes I also have:

    Add to Cart Null = name=$h_cart_nl
    Reset Item = name=$h_rSubmit_nl
    Check Out = name=$h_bSubmit_nl

    When I was in the testing phase of my code my comparison values were to be as expected with all of the hidden values(2nd grp of 3) being 1. At this point I was testing with one form, one item... no arrays, and my php and html were seperate entities.

    To put the whole thing together, the whole series of chips I have contained in a while loop reading from the text file in case the files are updated, I don't have to worry about the number of items.

    My first question is, Does php version 4.3 allow this type of behavior to be functional while using arrays? CGI 1.1 BTW...

    My second question is, why are my hidden values all " "?

    I also tested the value of $_POST against a hidden $_POST, and at least that is 1, however, this only changes to "Array" when my 'Check Out' button is pressed. Again my primary concern is whether or not I am doing this right meaning how much do I have to keep static(html) and dynamic(php)?

    If code is needed please request it. This email is lengthy enough and my php page in question is over 400 lines.

    Thanks,

    KW

  2. #2
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    $_POST is supoosed to be an array when a request is made using POST. It becomes an associative array with keys being equal to the value of the name= attribute of a form input, and the value being the value entered.

    I'm not sure I understand the rest of your question. Can you post a sample of what your form, what its submitting, and what you were expecting?

    Could you explain this part, as to me it doesn't make any sense :

    To put the whole thing together, the whole series of chips I have contained in a while loop reading from the text file in case the files are updated, I don't have to worry about the number of items.
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

  3. #3
    here's my whole file:

    <?php

    class event
    {

    var $ev;
    var $crt_nm;
    var $crt_val;
    var $crt_typ;
    var $crt_rdnm;
    var $crt_rdbtn_val;
    var $crt_rdbtn_typ;
    var $qty_inpt_nm;
    var $qty_inpt_typ;
    var $qty_mxln;
    var $qty_sz;
    var $rst_typ;
    var $rst_nm;
    var $rst_val;
    var $buy_nm;
    var $buy_typ;
    var $buy_val;

    function event($cart_name = "'Submit2\n'", $cart_val = "'Add to Cart\n'", $cart_type = "'submit\n'",
    $cart_rdname = "'radio\n'", $cart_rdbtn_val = "'radiobutton\n'", $cart_rdbtn_typ = "'radiobutton\n'",
    $qty_input_name = "'textfield\n'", $qty_input_type = "'text\n'",
    $qty_maxlen = "'3'", $qty_size = "'5'", $Reset_type = "'submit\n'", $Reset_name = "'Submit2\n'",
    $Reset_val = "'Reset\n'", $buy_name = "'Submit2\n'", $buy_type = "'submit\n'",
    $buy_value = "'Buy Now\n'", $secondSeries = "'74ALS Series\n'")
    {
    $this->ev = $secondSeries;
    $this->crt_nm = $cart_name;
    $this->crt_val = $cart_val;
    $this->crt_typ = $cart_type;
    $this->crt_rdnm = $cart_rdname;
    $this->crt_rdbtn_val = $cart_rdbtn_val;
    $this->crt_rdbtn_typ = $cart_rdbtn_typ;
    $this->qty_inpt_nm = $qty_input_name;
    $this->qty_inpt_typ = $qty_input_type;
    $this->qty_mxln = $qty_maxlen;
    $this->qty_sz = $qty_size;
    $this->rst_typ = $Reset_type;
    $this->rst_nm = $Reset_name;
    $this->rst_val = $Reset_val;
    $this->buy_nm = $buy_name;
    $this->buy_typ = $buy_type;
    $this->buy_val = $buy_value;
    }

    function set_me($cart_name, $cart_val, $cart_type, $cart_rdname, $cart_rdbtn_val, $cart_rdbtn_typ,
    $qty_input_name, $qty_input_type, $qty_maxlen,
    $qty_size, $Reset_type, $Reset_name, $Reset_val, $buy_name, $buy_type,
    $buy_value, $secondSeries)
    {
    $this->ev = $secondSeries;
    $this->crt_nm = $cart_name;
    $this->crt_val = $cart_val;
    $this->crt_typ = $cart_type;
    $this->crt_rdnm = $cart_rdname;
    $this->crt_rdbtn_val = $cart_rdbtn_val;
    $this->crt_rdbtn_typ = $cart_rdbtn_typ;
    $this->qty_inpt_nm = $qty_input_name;
    $this->qty_inpt_typ = $qty_input_type;
    $this->qty_mxln = $qty_maxlen;
    $this->qty_sz = qty_size;
    $this->rst_typ = $Reset_type;
    $this->rst_nm = $Reset_name;
    $this->rst_val = $Reset_val;
    $this->buy_nm = $buy_name;
    $this->buy_typ = $buy_type;
    $this->buy_val = $buy_value;
    }

    function get_me()
    {
    return $this->ev;
    return $this->crt_nm;
    return $this->crt_val;
    return $this->crt_typ;
    return $this->crt_rdnm;
    return $this->crt_rdbtn_val;
    return $this->crt_rdbtn_typ;
    return $this->qty_inpt_nm;
    return $this->qty_inpt_typ;
    return $this->qty_mxln;
    return $this->qty_sz;
    return $this->rst_typ;
    return $this->rst_nm;
    return $this->rst_val;
    return $this->buy_nm;
    return $this->buy_val;
    return $this->buy_typ;
    }

    function show_me()
    {print ("<div align=center /><tr /><td /><b>$this->ev</b></td></tr></div><br>");
    }

    function callshow_me($blah)
    {$blah->show_me();
    }

    function copy_me($ic, $icCrt_nm, $icCrt_typ, $icCrt_val, $icCrt_rdnm, $icCrt_rdbtn_val,
    $icCrt_rdbtn_typ, $icQty_inpt_nm, $icQty_inpt_typ,
    $icQty_mxln, $icQty_sz, $rst_nm, $rst_typ, $rst_val, $buy_nm, $buy_typ,
    $buy_val)
    {
    $this->ev = $ic->get_secondSeries();
    $this->crt_nm = $icCrt_nm->get_crt_nm();
    $this->crt_typ = $icCrt_typ->get_crt_typ();
    $this->crt_val = $icCrt_val->get_crt_val();
    $this->crt_rdnm = $icCrt_rdnm->get_crt_rdnm();
    $this->crt_rdbtn_val = $icCrt_rdbtn_val->get_crt_rdbtn_val();
    $this->crt_rdbtn_typ = $icCrt_rdbtn_typ->get_crt_rdbtn_typ();
    $this->qty_inpt_nm = $icQty_inpt_nm->get_qty_inpt_nm();
    $this->qty_inpt_typ = $icQty_inpt_typ->get_qty_inpt_typ();
    $this->qty_mxln = $icQty_mxln->get_Qty_mxln();
    $this->qty_sz = $icQty_sz->get_Qty_sz();
    $this->rst_nm = $rst_nm->get_rst_nm();
    $this->rst_typ = $rst_typ->get_rst_typ();
    $this->rst_val = $rst_val->get_rst_val();
    $this->buy_nm = $buy_nm->get_buy_nm();
    $this->buy_typ = $buy_typ->get_buy_typ();
    $this->buy_val = $buy_val->get_buy_val();
    }

    function showClick_var74ALS(&$e_ic)
    {
    $number = number_format($h_qText_nl,2);
    $price = number_format($cost,2);
    $total = number_format($cost,2) * number_format($qText,2);
    $cart_name = $cart;
    $qty_input_name = $qText;
    $Reset_name = $rSubmit;
    $h_rSubmit_nl = empty($rSubmit);
    $Reset_val = "'Reset\n'";
    $buy_name = $bSubmit;
    $h_bSubmit_nl = empty($bSubmit);
    $h_qText_nl = empty($qText);
    $secondSeries = "'74ALS Series\n'";

    $e_ic = fopen("74als.txt", "r");
    while(!feof($e_ic))
    {$out = array($view_ic);
    list ($id, $Qty, $des, $pins, $cost) = split( ',', $view_ic);
    $view_ic = fgets($e_ic, 4096);
    print "<div align=center><div align-center>";
    print ("<form method=$_POST[$qText] action=$_SERVER[PHP_SELF]>");
    print "<table align=center width=100% border=0 cellspacing=10>";
    print "<tr valign=top><td align=center colspan=6><hr 75%></td></tr>";
    print "<tr>";
    print "<td><div align=center><font face=Arial, Helvetica>";
    print "<h5>IC Number</h5></font></div></td>";
    print "<td><div align=center>";
    print "<font face=Arial, Helvetica><h5>Description</h5></font></div></td>";
    print "<td><div align=center>";
    print "<font face=Arial, Helvetica><h5>Pins</h5></font></div></td>";
    print "<td align=center><div align=center>";
    print "<font face=Arial, Helvetica><h5>Qty</h5></font></div></td>";
    print "<td align=center><div align=center>";
    print "<font face=Arial, Helvetica><h5>Cost</h5></font></div></td>";
    print "<td align=center><div align=center>";
    print "<font face=Arial, Helvetica><h5>Action</h5></font></div></td>";
    print "</tr><td align=center colspan=6><hr 75%></td></tr><td>";
    print "<div align=center>$id</div></td>";
    print "<td width=30%><div align=center>$des<br></div></td>";
    print "<td><div align=center>$pins</div></td><td align=center>";
    print "<div align=center>$Qty</div></td>";
    print "<td align=center>";
    print "<div align=center>$$cost</div><td></td>";
    print "<td align=center></td>";
    print "<td align=center colspan=6></td>";
    print "<tr valign=top></tr><tr valign=top>";
    print "<td width=5% rowspan=2 colspan=3 align=center></td>";
    print "<td width=10% rowspan=2 align=center>";
    print "<input type=text name=qText[] id=qText[] size=5 maxlength=3 value=></td>";
    print "<input type=hidden name=h_qText_nl>";
    print "<td width=15% rowspan=2 align=right></td><td width=15% rowspan=2 align=center>";
    print ('<input type=submit name=cart value="Add to Cart"><br>');
    print "<input type=hidden name=h_cart_nl>";
    print "<br>";
    print ('<input type=submit name=rSubmit value="Reset Item"></td>');
    print "<input type=hidden name=h_rSubmit_nl></tr><tr valign=top>";
    print "<td colspan=2></td></tr><tr valign=middle><td width=60% align=right colspan=3>Total:</td>";
    print "<td width=10% align=center>";
    if(qText == 0 && $h_cart_nl == FALSE) {
    $total = number_format($qText,3) * number_format($cost,2);}
    $call = '<script language="javascript">alert("Please call to confirm your order")</script>';
    if($qText % 2 == 0 && strpos($total,".") == FALSE)
    { switch(strlen($total) && strpos($total,"0")){
    case (strlen($total) == 2 && strpos($total,"0") == FALSE):
    print "a1 $";
    print $total;
    print ".00";
    break;
    case (strlen($total) == 2 && strpos($total,"0") == TRUE):
    print "b1 Total Display Val: $";
    print $total;
    print ".00";
    break;
    case (strlen($total) == 3 && strpos($total,"0") == FALSE):
    print "c1 $";
    print $total; print "0";
    break;
    case (strlen($total) == 3 && strpos($total,"0") == TRUE):
    print "d1 $";
    print $total;
    print ".00";
    break;
    case (strlen($total) == 4 && strpos($total,"0") == TRUE):
    print "e1 $";
    print $total;
    print "0";
    break;
    case (strlen($total) == 4 && strpos($total,"0") == FALSE):
    print "f1 $";
    print $total;
    print "<br>";
    break;
    case (strlen($total) == 5 && strpos($total,"0") == TRUE):
    print "g1 $";
    print $total;
    print "";
    break;
    case (strlen($total) == 5 && strpos($total,"0") == FALSE):
    print "h1 $";
    print $total;
    print ".00";
    break;
    case (strlen($total) > 5 && strpos($total,"0") == TRUE):
    print "i1 ";
    break;
    case (strlen($total) > 5 && strpos($total,"0") == FALSE):
    print "j1";
    break;} }
    elseif($qText % 2 == 0 && strpos($total,".") == TRUE)
    { switch(strlen($total) && strpos($total,"0"))
    { case (strlen($total) == 2 && strpos($total,"0") == FALSE):
    print "a2 $";
    print $total;
    print "0";
    break;
    case (strlen($total) == 2 && strpos($total,"0") == TRUE):
    print "b2 $";
    print $total;
    print ".00";
    break;
    case (strlen($total) == 3 && strpos($total,"0") == FALSE):
    print "c2 $";
    print $total; print "0";
    break;
    case (strlen($total) == 3 && strpos($total,"0") == TRUE):
    print "d2 $";
    print $total;
    print "0";
    break;
    case (strlen($total) == 4 && strpos($total,"0") == TRUE):
    print "e2 $";
    print $total;
    print "0";
    break;
    case (strlen($total) == 4 && strpos($total,"0") == FALSE):
    print "f2 $";
    print $total;
    print "";
    break;
    case (strlen($total) == 5 && strpos($total,"0") == TRUE):
    print "g2 $"; print $total;
    print "0";
    break;
    case (strlen($total) == 5 && strpos($total,"0") == FALSE):
    print "h2 $"; print $total;
    print ".00";
    break;
    case (strlen($total) > 5 && strpos($total,"0") == TRUE):
    print "i2 ";
    break;
    case (strlen($total) > 5 && strpos($total,"0") == FALSE):
    print "j2 "; break;} }
    elseif($qText % 2 == 1 && strpos($total,".") == FALSE)
    { switch(strlen($total) && strpos($total,"0"))
    { case (strlen($total) == 2 && strpos($total,"0") == FALSE):
    print "a3 $";
    print $total;
    print ".00";
    break;
    case (strlen($total) == 2 && strpos($total,"0") == TRUE):
    print "b3 $"; print $total; print ".00";
    break;
    case (strlen($total) == 3 && strpos($total,"0") == FALSE):
    print "c3 $";
    print $total;
    print "0";
    break;
    case (strlen($total) == 3 && strpos($total,"0") == TRUE):
    print "d3 $";
    print $total;
    print "0";
    break;
    case (strlen($total) == 4 && strpos($total,"0") == TRUE):
    print "e3 $";
    print $total;
    print "0";
    break;
    case (strlen($total) == 4 && strpos($total,"0") == FALSE):
    print "f3 $";
    print $total;
    print "";
    break;
    case (strlen($total) == 5 && strpos($total,"0") == TRUE):
    print "g3 $";
    print $total;
    print "";
    break;
    case (strlen($total) == 5 && strpos($total,"0") == FALE):
    print "h3 $";
    print $total;
    print ".00";
    break;
    case (strlen($total) > 5 && strpos($total,"0") == TRUE):
    print "i3 ";
    break;
    case (strlen($total) > 5 && strpos($total,"0") == FALSE):
    print "j3 ";
    break;} }
    elseif($qText % 2 == 1 && strpos($total,".") == TRUE)
    { switch(strlen($total) && strpos($total,"0"))
    { case (strlen($total) == 2 && strpos($total,"0") == FALSE):
    print "a4 $";
    print $total;
    print "";
    break;
    case (strlen($total) == 2 && strpos($total,"0") == TRUE):
    print "b4 $";
    print $total;
    print ".00";
    break;
    case (strlen($total) == 3 && strpos($total,"0") == FALSE):
    print "c4 Total Display Val: $"; print $total; print "0
    "; break;
    case (strlen($total) == 3 && strpos($total,"0") == TRUE):
    print "d4 $";
    print $total;
    print "0";
    break;
    case (strlen($total) == 4 && strpos($total,"0") == TRUE):
    print "e4 $";
    print $total;
    print "";
    break;
    case (strlen($total) == 4 && strpos($total,"0") == FALSE):
    print "f4 $";
    print $total;
    print "";
    break;
    case (strlen($total) == 5 && strpos($total,"0") == TRUE):
    print "g4 $";
    print $total;
    print "";
    break;
    case (strlen($total) == 5 && strpos($total,"0") == FALSE):
    print "h4 $";
    print $total;
    print ".00";
    break;
    case (strlen($total) > 5 && strpos($total,"0") == TRUE):
    print "i4 Total Display Val: $";
    print $total;
    print "";
    break;
    case (strlen($total) > 5 && strpos($total,"0") == FALSE):
    print "j4 ";
    break;} }
    else {print $call . "<br>";}
    print "</td>";
    print "<input type=hidden name=h_Total_nl><td width=15% align=right></td>";
    print "<td width=15% align=center>";
    print ('<input type=submit name=bSubmit value="Check Out"></td>');
    print "<input type=hidden name=h_bSubmit_nl></tr></table></form></div></div>";


    print "string length total: " . strlen($total) . "<br>";
    print "substring total -4: " . substr($total, -4) . "<br>";
    print "substring total -3: " . substr($total, -3) . "<br>";
    print "substring total -2: " . substr($total, -2) . "<br>";
    print "substring total -1: " . substr($total, -1) . "<br>";
    print "substring total 4: " . substr($total, 4) . "<br>";
    print "substring total 3: " . substr($total, 3) . "<br>";
    print "substring total 2: " . substr($total, 2) . "<br>";
    print "substring total 1: " . substr($total, 1) . "<br>";
    $p_null = empty($_POST);
    print "post null: " . $p_null . "<br>";
    print "Text Val: " . $qText . "<br>";
    print "Hidden Text Val: " . $h_qText_nl . "<br>";
    print "Total Hidden Val: " . $h_Total_nl . "<br>";
    print "Reset Val: " . $rSubmit . "<br>";
    print "Hidden Reset Val: " . $h_rSubmit_nl . "<br>";
    print "a" . $cart . "<br>";
    print "b" . $h_cart_nl . "<br>";
    print "Reset Message: " . $rmsg . "<br>";
    print "Total mod 1: <br>";
    print "Refreshed. <br>";
    print "Display Page: " . $_SERVER[PHP_SELF] . "<br>";
    print "post: " . $_POST . "<br>";
    if ($_POST == $out){
    print "The arrays are equal. <br>";}
    else
    {print "The arrays are not equal. <br>";}
    if(isset($_POST)){
    print "post is set <br>";}
    if(isset($rSubmit)){
    print "reset is set <br>";}
    else
    {print "you still have a lot of work to do!! Reset is not set. <br>";}
    if(isset($cart)){
    print "cart is set <br>";}
    else
    {print "you still have a lot of work to do!! Cart is not set. <br>";}
    foreach ($_POST as $key => $value){
    print "post" . $key . ":" . $value . "<br>";}
    foreach ($out as $key => $value)
    { print "item " . $key . ": " . $value . "<br>";}
    print "http values: " . $HTTP_POST_VARS[$qText] . "<br>";

    }
    }
    }

    $order = new event;
    $order->showClick_var74ALS(&$e_ic);

    ?>


    the web page that is displayed is:

    nrs1 dot com slash New slash 74als.php

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •