insert proccess whith looping in php

firstly sorry my english is bad then i have problem i try to make lopping insert into table but i have problem i can't make array for inputs to can insert in table with looping from another table maybe u can't understand me but look to the code and u will understand my problem

           $select = mysql_query("SELECT * FROM table_name   ");
    ?>
    <form method="post" action="">
    <?
    while($row =mysql_fetch_array($select))
    {
          if($_POST['add'])
        {
    $updpol = mysql_query("insert into table_name2                             (yes,no,maybe,g_id)
values           
                 ('".$_POST['yes']."','".$_POST['no']."','".$_POST['maybe']."','".$row['id']."')
                                  ")
        }
          else{
    ?>
    <input type="checkbox" name="yes" value="1" /> 
    <br />
    <input type="checkbox" name="no" value="1" />
    <br />
    <input type="checkbox" name="maybe" value="1" /> 

    <?


    }
    ?>
    <input type="submit" name="add_poll" value="submit"  />
    </form>

Answers


in your php code , your checking if:

if($_POST['add'])

While there's no input named add in your form. I believe you meant:

if($_POST['add_poll'])

In order to have multiply instances of inputs , you can do something like:

   <input type="checkbox" name="yes[]" value="1" /> 
    <br />
    <input type="checkbox" name="no[]" value="1" />
    <br />
    <input type="checkbox" name="maybe[]" value="1" /> 

So , now , when posted:

$_POST['yes'] is an array of all the checkboxes. And as an array , it starts with $_POST['yes'][0] and continues $_POST['yes'][1] and so on.

Therefore:

           $select = mysql_query("SELECT * FROM table_name   ");
    ?>
    <form method="post" action="">
    <?
    $i = 0;
    while($row =mysql_fetch_array($select))
    {
          if($_POST['add_poll'])
        {
    $updpol = mysql_query("insert into table_name2                             (yes,no,maybe,g_id)
values           
                 ('".$_POST['yes'][$i]."','".$_POST['no'][$i]."','".$_POST['maybe'][$i]."','".$row['id']."')
                                  ");
        $i++;
        }
          else{
    ?>
    <input type="checkbox" name="yes[]" value="1" /> 
    <br />
    <input type="checkbox" name="no[]" value="1" />
    <br />
    <input type="checkbox" name="maybe[]" value="1" /> 

    <?


    }
    ?>
    <input type="submit" name="add_poll" value="submit"  />
    </form>

Need Your Help

Convert two separate Sets to a 2D array

java swing collections jtable set

I have two Sets of Strings, with each in the following format:

Drupal parsing JSON to iPhone

json drupal drupal-7 drupal-modules

Bellow is the code for a custom module that parses json to ios devices. The thing is on my drupal page I've created a node hierarcy using "nodehierarcy" module. I've got two types of custom content...