473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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&action=form&op=order\ " name=\"order\" >\n";


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

while ($record_k = mysql_fetch_array($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($sql_pk) or die(mysql_error());

while ($record_pk = mysql_fetch_array($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($sql_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_array($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&action=add\">";
echo "<div class=\"pro\>$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>"; }
else



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

echo"<form method=\"post\" action=\"index.php?page=cart&action=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 `".$dbtablesprefix."basket` ( `CUSTOMERID` , `PRODUCTID` , `STATUS` , `ORDERID` , `LINEADDDATE` , `QTY` , `FEATURES`) VALUES ( '" . $customerid . "', '" . $prodid . "', 'BASKET', '0' , '" . Date("d-m-Y @ G:i") . "' , '" . $numprod . "', '".$productfeatures. "')";[/PHP]
Mar 27 '08 #1
4 1714
aktar
105 100+
Use HTML arrays to get the product details

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

Expand|Select|Wrap|Line Numbers
  1. $query = "
  2. INSERT INTO `".$dbtablesprefix."basket` ([FIELD NAMES]) VALUES ([VALUES]);
  3.  
  4. INSERT INTO `".$dbtablesprefix."basket` ([FIELD NAMES]) VALUES ([VALUES]);
  5.  
  6. INSERT INTO `".$dbtablesprefix."basket` ([FIELD NAMES]) VALUES ([VALUES]);
  7.  
  8. INSERT INTO `".$dbtablesprefix."basket` ([FIELD NAMES]) VALUES ([VALUES]);";
Mar 29 '08 #2
ronverdonk
4,258 Expert 4TB
Use HTML arrays to get the product details

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

Expand|Select|Wrap|Line Numbers
  1. $query = "
  2. INSERT INTO `".$dbtablesprefix."basket` ([FIELD NAMES]) VALUES ([VALUES]);
  3.  
  4. INSERT INTO `".$dbtablesprefix."basket` ([FIELD NAMES]) VALUES ([VALUES]);
  5.  
  6. INSERT INTO `".$dbtablesprefix."basket` ([FIELD NAMES]) VALUES ([VALUES]);
  7.  
  8. INSERT INTO `".$dbtablesprefix."basket` ([FIELD NAMES]) VALUES ([VALUES]);";
aktar: And how do you suggest that your multi query is executed?

Ronald
Mar 29 '08 #3
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
Mar 29 '08 #4
ronverdonk
4,258 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [prodid] => Array
  4.         (
  5.             [0] => ABC
  6.             [1] => DEF
  7.             [2] => GHI
  8.         )
  9. )
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
Mar 29 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: cody | last post by:
We have a huge project, the solutuion spans 50 projects growing. Everytime I want to start the project I have to wait nearly over 1 minute for the compiler to complete building. This is...
10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
16
by: Philippe C. Martin | last post by:
Hi, I am trying to change the data in a form field from python. The following code does not crash but has no effect as if "form" is just a copy of the original html form. Must I recreate the...
3
by: vonclausowitz | last post by:
Hi Everyone, Is it possible to create some code which can automatically update my forms formatting? I have a small database with a form which is periodically changed. When the db is returned to...
4
by: Alex Sibilev | last post by:
Hello, I have a really weird problem I've been trying to solve it without any luck for the last couple of hours :( I'm writing a "conference board" application (quite similar to ASP.NET...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
19
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash...
14
by: yxq | last post by:
Hello, I want to build the multi-language application with the xml file, how to do? could anyone tell a sample? Thank you
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.