homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Form Options

 10:03 pm on Mar 25, 2003 (gmt 0)

I am using PHP/mySQL and I am trying to find out the best way to get some information into a form into my database. I know how to do this when it is very straightforward entry but what if there are multiple ways that my users need to enter information.

This is not for a shipping cart. Basically they need to enter the type of a widget, then size and quantity of that item. I have a standard table that this information goes in to. Now, this is easy to do, but what I don't understand how to implement is sometimes the user needs to enter multiple types of widgets then the size and quantity of that type as well. The form only has options to enter one. Is there a way to have it so if a user clicks 'add another type' basically another <tr> pops up under the last one with new fields to enter the info? I don't want to have to put a whole bunch of rows there when most of the time they only need one row.

Is there a way to do that and then when the user click submit the info goes into multiple rows in a table.

Am I even making sense? heh

Thanks for looking.




 10:08 pm on Mar 25, 2003 (gmt 0)

>>Am I even making sense?

yes you are, strangely. ;)

It would depend on how it all works. Might you have the option before they get to that page to have them choose how many entries they need?

I think for the click and add a row you could post to itself maybe and load the desired number of rows with the default being one. Then reload the posted data into the existing rows.


 10:17 pm on Mar 25, 2003 (gmt 0)

That might work, I also thought it was somehow possible to have dynamic forms with javascript, but them I wouldnt know how to make sure the field names would get entered correctly when submitted. I think I am confusing myself all too much.


 10:43 pm on Mar 25, 2003 (gmt 0)

well if you do it in php then just create the form dynamically and have the field names be the same and append a number to the end.

product1 price1 quantity1
product2 price2 quantity2
product3 price3 quantity3

easy to create dynamically and parse values after. The processing script could do something like

$counter = 1;
while (isset(${product . $counter})) {
do stuff;

the form could be built with the rownum
echo "<form name=blah action=something>";
$counter = 1;
while ($counter <= $rownum) {
echo "<input type=text name=product",$counter,">";
echo "<input type=text name=price",$counter,">";
echo "<input type=text name=quantity",$counter,">";
echo "</form>";

or something like that.


 3:30 am on Mar 26, 2003 (gmt 0)

Cool thanks jatar_k, I think I've got it!


 11:31 am on Mar 26, 2003 (gmt 0)

You donīt really need to append a number to the end of the form [w3.org] element names. If multiple form [w3.org] elements have the same name PHP [php.net] will turn them into arrays.



 2:43 pm on Mar 26, 2003 (gmt 0)

You will have to add [] though.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved