Jump to content

Multiple Form Textbox Problem


samsina

Recommended Posts

I have problem. So at work I am making this gigantic form, everything done except this part.

 

here is the database view:

 

      name, phone    , type

ex:  sam , 12345678, installation

ex:  jim  ,  12222222, support

 

html view (fixed size of three for each):

 

install

name:_____  phone:______

name:_____  phone:______

name:_____  phone:______

 

support

name:_____  phone:______

name:_____  phone:______

name:_____  phone:______

 

submit

 

so basically the form includes from contact lists

1)installation group

2)support group

 

into one database. the easier way to name each field as a unique text boxes and process them one at a time... any efficient way?

Link to comment
https://forums.phpfreaks.com/topic/59865-multiple-form-textbox-problem/
Share on other sites

try something like this

 

<?php
if (isset($_GET['sub']))
{
    foreach ($_GET['name'] as $type=>$names)
    {
        foreach ($names as $k => $name) {
            $phone =  $_GET['phone'][$type][$k];
            
            $sql = "INSERT INTO mytable (name, phone,type)
                    VALUES ('$name', '$phone', $type')";
                    
            echo "<pre>$sql</pre>";   // update here
        }
    }
}

?> 
<form>
<h3>Installation</h3>
<?php
for ($i=0; $i<3; $i++)
{
echo <<<TXT
Name <input type="text" name="name[installation][$i]">
Phone <input type="text" name="phone[installation][$i]"> <br />
TXT;
}
?>
<h3>Support</h3>
<?php
for ($i=0; $i<3; $i++)
{
echo <<<TXT
Name <input type="text" name="name[support][$i]">
Phone <input type="text" name="phone[support][$i]"> <br />
TXT;
}
?>
<input type="submit" name="sub" value="Submit">
<form> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.