Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003

    Unanswered: multiple row mysql inserts using checkbox

    Hello all...

    I am trying to figure out how to populate a "main" db from a "limbo" db. I can query the "limbo" db and using printf, have a nice page output of records. What I want to do now is, those records that are "checked" using a checkbox, are the only ones that will get processed into the "main" db.

    I do a basic mysql query from the source db easy enough and get the desired php page with a checkbox:

    $result = mysql_query("
    SELECT *
    FROM $tablesource
    ORDER BY for_id

    for($i = 0; $i < count($myrow); ) {
    while ($row = mysql_fetch_row($result)) {

    $for_id = $row[0];
    $for_rec = $row[12];

    printf( "
    <tr bgcolor=\"$bgcolor\">
    <td colspan=3><b>Corrective Action:</b> %s</td>
    <td> %s </td>
    <td> <input name='SB' type='checkbox' id='SB' value='1' $SB > </td>

    } //while loop
    } //for i loop

    No problems there. What I cannot mentally get a handle on is how to insert all the items that are checked off into the destination table. I have done insert hundreds of times with "single" form pages. I'm thinking I have to "loop" an insert, but I have failed on getting on to work properly.

    mysql_query( "insert into $tabledest (
    ) VALUES (

    if (mysql_errno()!=0) {
    switch (mysql_errno()) {
    echo "Error #".mysql_errno(). " (".mysql_error(). ")<br>";

    Thanks in advanced for any direction / ideas... ron

  2. #2
    Join Date
    May 2005
    <input name='SB' type='checkbox' id='SB' value='$row[0]'>

    this will give you a PHP array

    this array will contain all the values which need to be copied. setup a loop.

  3. #3
    Join Date
    Jul 2003
    Thanks!!! Then reading the answer, it's almost like.. duh! Bahahhaha..

    Here's a somewhat simplified solution that I implemented. Two loops; one to build the initial array and web page form for the user from a source table to approve items with a radio button, then the another, as suggested, to evaluate what has been approved and process that record into the destination table.

    Ran a "do" loop with $index++ and $index_count++

    $ApprovedStr = Approved.$index;
    $for_obStr = for_ob.$index;

    In a printf statement:
    <input type=hidden name=\"$for_obStr\" value=\"$row[11]\">
    <input type=radio name=%s value=-1>Yes
    <input type=radio name=%s value=0 checked>No

    the last two each getting a value of $ApprovedStr

    Then doing a For using the $index_count value,

    for ($index = 0; $index <= $counter; $index++) {

    $for_obvalue = ${'for_ob'.$index};
    if ($Approvedvalue == '-1')
    mysql_query( "INSERT INTO $table (
    ) VALUES (
    } // end of If Approved
    } // end of For loop

    Much thanks... ron

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts