mariocesar Posted December 20, 2007 Share Posted December 20, 2007 hi, I got this table is working fine but just the first row is upload in to my sql table, how can I feed the complete info all 11 rows at once, here is the code (table): <form method="POST" action="dumpinfo.php" name="form" > <table width="750" cellspacing="1" cellpadding="3" > <tr> <td><div align="center">productid</div></td> <td><div align="center">baseprice</div></td> <td><div align="center">quantity</div></td> <td><div align="center">5peroff</div></td> <td><div align="center">10peroff</div></td> <td><div align="center">15peroff</div></td> <td><div align="center">20peroff</div></td> <td><div align="center">25peroff</div></td> <td><div align="center">30peroff</div></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr> <td><font color="#003366" > <input name="productid" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="baseprice" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="quantity" type="text" size="12"> </font></td> <td><font color="#003366" > <input name="fiveperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="tenperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="fifperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="twfperoff" type="text" size="8"> </font></td> <td><font color="#003366" > <input name="thrperoff" type="text" size="8"> </font></td> </tr> <tr><td colspan="9" align="center"><input type="submit" name="Submit2" value="Submit" onClick="return validate(form)"> <INPUT type="reset" value="Cancel"> </td></tr> </table></form> //and here is the php script: <?php /////////////////////// CONNECT TO MYSQL DB //////////////////// // OPEN CONNECTION ---> $connection=mysql_connect('securebut', $user = "productdetail", $pass = "loco07") or die("Unable to connect!"); /* change this! */ mysql_select_db("productdetail") or die("Unable to select database!"); /* change this! */ // EXECUTE QUERY ---> $query="INSERT INTO productdetail ( productid, baseprice, quantity, 5peroff, 10peroff, 15peroff, 20peroff, 25peroff, 30peroff) VALUES( '".$productid."', '".$baseprice."', '".$quantity."', '".$fiveperoff."', '".$tenperoff."', '".$fifperoff."', '".$twperoff."', '".$twfperoff."', '".$thrperoff."')"; //////-----> $result=mysql_query($query) or die("Error in query:".mysql_error()); if ($result) echo mysql_affected_rows()." Thanks, Mario a record was inserted into the database effectively, go back and insert the next one, You are the Best"; // CLOSE CONNECTION ---> mysql_close($connection); ?></td></table> Thanks in advance. Quote Link to comment Share on other sites More sharing options...
asmith Posted December 20, 2007 Share Posted December 20, 2007 well with such coding you can't , but it is easy to solve. put a " [] " next to each name of an input . like : <input name="productid[]" type="text" size="8"> now when you click submit it will post an array to your script containing your values . so all the 11 rows for the input with name name="productid[]" will be in : $_POST[productid] which can access by : $_POST[productid][0] $_POST[productid][1] $_POST[productid][2] $_POST[productid][3] till [10] . now that you have it , set a counter for each 11 in the script : $i = 0 while ($i < 11) { $query="INSERT INTO productdetail ( productid, baseprice, quantity, 5peroff, 10peroff, 15peroff, 20peroff, 25peroff, 30peroff) VALUES( '".$_POST[productid][$i]."', '".$_POST[baseprice][$i]."', ... // do for all the values //////-----> $result=mysql_query($query) or die("Error in query:".mysql_error()); if ($result) echo mysql_affected_rows()." Thanks, Mario a record was inserted into the database effectively, go back and insert the next one, You are the Best"; $i++; } Quote Link to comment Share on other sites More sharing options...
mariocesar Posted December 20, 2007 Author Share Posted December 20, 2007 thanks, but gives me an error: Parse error: parse error, unexpected T_WHILE in /home/content/m/a/r/mariovicuna/html/dumpinfo.php on line 17 while ($i < 11) is line 17: $i = 0 while ($i < 11) { Quote Link to comment Share on other sites More sharing options...
asmith Posted December 20, 2007 Share Posted December 20, 2007 the part $i = 0 has no " ; " at the end . change it : $i = 0; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.