How to build a big form from sql then send it back to db with changes.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tester1000
    New Member
    • Mar 2008
    • 2

    How to build a big form from sql then send it back to db with changes.

    Hi first ... sorry for my english :-(

    I have a webshop and i wana make a form for all product what i have .
    Product name ( textbox ) . after i bit the nr ( qty) in the text box i would to send it to my shoping card ( $_GET $numprod ,$prodid, $basketid ) .

    my problem is i can only send 1 product at the time becouse i dont have the product in array.How can put in array all the forms in array than inser into db
    can sameone help me to figure out this?


    the form :

    [PHP]function form( )

    {
    echo "<table align=\"center\ " border=\"0\" class=\"sadrzaj \" align=\"center\ " width=\"400\" cellpadding=\"3 \">";
    echo "<form method=\"post\" action=\"index. php?page=list&a ction=form&op=o rder\" name=\"order\" >\n";


    $sql_k = "SELECT ID, NAME FROM shopgroup ORDER BY ID ASC";
    $result_k = mysql_query($sq l_k) or die(mysql_error ());

    while ($record_k = mysql_fetch_arr ay($result_k)) // list group
    {
    echo "<table align=\"center\ " border=\"0\" class=\"sadrzaj \" align=\"center\ " width=\"400\" cellpadding=\"3 \">";

    echo "<div class=\"nazivi\ "> $record_k[NAME] </div></table>";

    $sql_pk = "SELECT * FROM shopcategory WHERE GROUPID = '$record_k[ID]'";
    $result_pk = mysql_query($sq l_pk) or die(mysql_error ());

    while ($record_pk = mysql_fetch_arr ay($result_pk)) // list categorie
    {


    $sql_p = "SELECT ID, PRODUCTID, PRICE
    FROM shopproduct
    WHERE CATID = $record_pk[ID]
    ORDER BY PRODUCTID ASC";

    $result_p = mysql_query($sq l_p) or die(mysql_error ());
    $i = 1;


    echo "<table align=\"center\ " border=\"0\" width=\"400\" class=\"listek\ " cellpadding=\"7 \">\n";
    echo "<caption >$record_pk[DESC]</caption>";
    //echo $customerid;
    echo "<tr><td>\n ";

    while ($record_p = mysql_fetch_arr ay($result_p)) // list product
    {

    if($i%4==0)
    {


    //echo "<table align=\"center\ " border=\"0\" class=\"sadrzaj \" align=\"center\ " width=\"400\" cellpadding=\"3 \">";

    echo"<form method=\"post\" action=\"index. php?page=cart&a ction=add\">";
    echo "<div class=\"pro\>$r ecord_p[PRODUCTID] <input type=\"text\" name=\"numprod\ " size=\"5\" /><input type=\"submit\" value=\"OK\" name=\"sub\">";
    echo "<input type=\"hidden\" name=\"prodid\" value=\"$record _p[ID]\">";
    echo"</form></div>"; }
    else



    // echo "<table align=\"center\ " border=\"0\" class=\"sadrzaj \" align=\"center\ " width=\"400\" cellpadding=\"3 \">";

    echo"<form method=\"post\" action=\"index. php?page=cart&a ction=add\">";
    echo "<div class=\"pro\ width=\"100\">$ record_p[PRODUCTID] <input type=\"text\" name=\"numprod\ " size=\"5\" /><input type=\"submit\" value=\"OK\" name=\"sub\">";
    echo "<input type=\"hidden\" name=\"prodid\" value=\"$record _p[ID]\">";
    echo"</form></div>";


    $i++;
    }

    echo "</td></tr>";
    echo "</table><br /><br />";
    }


    }
    echo "<hr class=\"red\" />
    <div style=\"text-align:right\">
    <input type=\"submit\" name=\"sub\" value=\"order all\" class=\"big\" \" />
    </form></div><br />\n";

    }[/PHP]



    and the inster at now for one product

    [PHP]$query = "INSERT INTO `".$dbtablespre fix."basket` ( `CUSTOMERID` , `PRODUCTID` , `STATUS` , `ORDERID` , `LINEADDDATE` , `QTY` , `FEATURES`) VALUES ( '" . $customerid . "', '" . $prodid . "', 'BASKET', '0' , '" . Date("d-m-Y @ G:i") . "' , '" . $numprod . "', '".$productfeat ures. "')";[/PHP]
  • aktar
    New Member
    • Jul 2006
    • 105

    #2
    Use HTML arrays to get the product details

    you would then create multiple entries of INSERT based on the HTML data

    [CODE=php]$query = "
    INSERT INTO `".$dbtablespre fix."basket` ([FIELD NAMES]) VALUES ([VALUES]);

    INSERT INTO `".$dbtablespre fix."basket` ([FIELD NAMES]) VALUES ([VALUES]);

    INSERT INTO `".$dbtablespre fix."basket` ([FIELD NAMES]) VALUES ([VALUES]);

    INSERT INTO `".$dbtablespre fix."basket` ([FIELD NAMES]) VALUES ([VALUES]);";[/CODE]

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Originally posted by aktar
      Use HTML arrays to get the product details

      you would then create multiple entries of INSERT based on the HTML data

      [CODE=php]$query = "
      INSERT INTO `".$dbtablespre fix."basket` ([FIELD NAMES]) VALUES ([VALUES]);

      INSERT INTO `".$dbtablespre fix."basket` ([FIELD NAMES]) VALUES ([VALUES]);

      INSERT INTO `".$dbtablespre fix."basket` ([FIELD NAMES]) VALUES ([VALUES]);

      INSERT INTO `".$dbtablespre fix."basket` ([FIELD NAMES]) VALUES ([VALUES]);";[/CODE]
      aktar: And how do you suggest that your multi query is executed?

      Ronald

      Comment

      • tester1000
        New Member
        • Mar 2008
        • 2

        #4
        so,,,
        1.:and how shold i creae the array and $_POST it
        2.: $_GET this array and splitt it to 1 line ?

        I could only insert after splitting it becaus the send ( name="prodid" and name"numprod" ) is all the same only the value is different. see my code

        it now i have by all product a send button :-( but this is not so good . i have over 500 product

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          You can make a HTML array by appending the array identifier [] (open-close square brachets) to the name field in the <input> statement. Like[php]echo "<input type='hidden' name='prodid[]' value='$record_ p[ID]'>";[/php]When the form is posted, you will have an array with index 'prodid' in the $_POST array.

          Sample: you have a form with 3 input fields with products stored in prodid[]. Prodid values in the form are 'ABC', 'DEF' and 'GHI'. The form is now submitted. The posted script now has these 3 values in an array in the $_POST array. When you would do a print_r($_POST) in that posted script, you would see:
          Code:
          Array
          (
              [prodid] => Array
                  (
                      [0] => ABC
                      [1] => DEF
                      [2] => GHI
                  )
          )
          Now you can read that array, example:[php]foreach($_POST['prodid'] as $val) {
          ... $val now contains one prodid ...
          ... code to process one prodid ....
          }[/php]Okay?

          Ronald

          Comment

          Working...