Update many records via checkbox and pagination

Hello

I am a newbie to PHP. I am currently writing a PHP screen, where i want to be able to tick many records via checkbox and update themat the same time. Also I want the records displayed in pagination. I have written the code below, the pagination and record display works, but the records when selected and I press the submit button, nothing happens. Please can someone put me on the right path? The code is below.

<?php

// include needed files
require('../db_config.php');
require('../global.php');
require("../lib/Pager.class.php");

// connect to the database
db_connect($mysql['username'], $mysql['password'], $mysql['database'],$mysql['host']);

// assign config options from database to an array
$config = get_config($mysql['prefix']);

debug_mode($config['debug_mode']);


// start the session
admin_sessions($config['admin_session_expire']);
if (!isset($_SESSION['logged_in']))
{
    redirect('./login.php');
}
// start class
$p = new Pager;

// gert member type description
if(isset($_GET['description']))
{
    $memberType = $_GET['memberType'];
    }

$max = 10; //amount of articles per page. change to what to want
$p = $_GET['p'];
if(empty($p))
{
$p = 1;
}
$limits = ($p - 1) * $max; 

$sql1="select id from members_memberType where description = '".$_GET['memberType']."'" ;
$result=mysql_query($sql1);
$row = mysql_fetch_array($result);
$memberTypeId = $row['id'];
if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];
if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])
 
$id = "('" . implode( "','", $checkbox ) . "');" ;
$sql="UPDATE members_users SET memberTypeid = ".$memberTypeId." WHERE id in $id" ;
$result = mysql_query($sql) or die(mysql_error());
}
//view the news article!
if(isset($_GET['act']) && $_GET['act'] == "view")
{

while($r = mysql_fetch_array($sql))
{

echo "<div><p>$title</p><p>$author</p><p>$story</p></div>";
}

}else{

//view all the news articles in rows
$sql = mysql_query("SELECT * FROM vwUserMemberType where description = '".$_GET['memberType']."' LIMIT ".$limits.",$max") or die(mysql_error());
$result=mysql_query($sql);
//the total rows in the table
$totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM vwUserMemberType where description = '".$_GET['memberType']."'"),0);    
//the total number of pages (calculated result), math stuff...
$totalpages = ceil($totalres / $max); 
//the table
    echo "<html>";
                echo "<head>";  
                echo "<title>View Children Records</title>";
                print '<link href="../images/admin.css" rel="stylesheet" type="text/css" media="all" />' ;     
                print '<meta http-equiv="Content-Type" content="text/html"; charset=utf-8"/>';
                print '<script type="text/javascript" src="../images/hint.js">';
                print '<table width="549" border="0" align="center" cellpadding="0" cellspacing="0">';
                print '</script>';
                print '</head>';
                print '<body link="white" vlink="white"  <font color="white"/>';
                print '<table align="center">';
                print '<tr>';
                print '<td align="center" width="100%" height="58"><img src="../images/header_logo.gif" width="252" height="58" border="0"  /></a></td>';
                print '</tr>';
                print '</table>';
                print '<tr>';
                print '<td height="2"><img src="../images/grey_pixel.gif" width="100%" align="center" height="2" /></td>';
                print '</tr>';
                echo '<table border="0" align="center" cellpadding="10" >';
                echo '<tr>';
                echo '<td><h1> <font color="#FFFFFF">View Children Records</font></h1></td> ';
            //    echo "<h1>View Children Records</h1>";
            //    echo '</td>';
                echo '</tr>';
                echo '</table>'; 
echo '<table border="1" align="center" cellpadding="10" >';
echo '<tr align="right"><th> <font color="white"/> First Name</th> <th><font color="white"/> Last Name</th><th><font color="white"/> Date of birth</th><th></th> <th></th></tr>';
while($r = mysql_fetch_array($sql))
{
//echo "<td><a href='viewChildren.php?act=view&id=$id'>$title</a></td><td>$author</td>";

    $ID = $r['id'];
    $description=$r['description'];
    $FrstName=$r['firstname'];
    $cSurname=$r['lastname'];
    $membertypeid=$r['membertypeid'];
    
 
    echo '<tr  align="right">';
    echo '<td> <font color="white"/>' . $membertypeid . '</td>';
    echo '<td> <font color="white"/>  ' . $description . '</td>';
    echo '<td> <font color="white"/> ' . $FrstName . '</td>';
    echo '<td> <font color="white"/> ' . $cSurname . '</td>';
    echo '<td align="center" width="22%" class="style2"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $ID; ?>"></td>';

    echo '<td>  <font color="white"/> <a href="change_form.php?id=' . $ID . '">Edit</a></td>';
   // echo '<td>  <font color="white"/> <a href="editChild.php?id=' . $ID . '">Edit</a></td>';
    echo '<td>  <font color="white"/> <a href="delete_form.php?id=' . $ID . '">Delete</a></td>';
                               echo "</tr>";
                    //           $i++;
                               }
                     // close table>
                     for($i = 1; $i <= $totalpages; $i++){ 
                     echo "<tr>";
                     echo '<td border="1" align="right">';
                     echo "<a href='userlistScratch.php?memberType=$description&p=$i' align='right'>Page   $i   </a>|";    
                     echo "</td>";
                     echo "</tr>";
                     }
                               echo "</table>";
}
//close up the table
//echo "</tr></table>";


?>
<table align="right" width="50%">
<tr align="right">
<td align="center"><input name="activate" type="submit" id="activate" value="Assign to <?  echo '' . $_GET['memberType'] . ''; ?>"</td>
</tr>
</table>
       <table border="0" align="center" cellpadding="10" >
                <td><a href="./index.php" class="style2">Return to Admin Panel</a>
                </td>
                </tr>
       </table>
                
        </body>
</html>
</html>

Try this

$id = "('" . implode( "','", array_values($checkbox) ) . "');" ;

Thanks SgtLegend, I have got it working now. All I did was I changed one line of code from

echo '<td align="center" width="22%" class="style2"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $ID; ?>"></td>'

to

echo '<td align="center" width="22%" class="style2"><input name="checkbox[]" type="checkbox" id="checkbox[]" value='. $ID .'></td>';

After a further investigation, I found out that the value of $ID was not being picked up from the first code, so I changed it to the second,

Thanks, the problem that I have now is that when I click on the command button, nothing happens. Please help

I have made some progress. What happens now is that when I click on the assign button, the screen refreshes, but the update code is not run, because none of the selected records are updated. Please can anyone point me to the right direction?

<?php

// include needed files
require('../db_config.php');
require('../global.php');
require("../lib/Pager.class.php");

// connect to the database
db_connect($mysql['username'], $mysql['password'], $mysql['database'],$mysql['host']);

// assign config options from database to an array
$config = get_config($mysql['prefix']);

debug_mode($config['debug_mode']);


// start the session
admin_sessions($config['admin_session_expire']);
if (!isset($_SESSION['logged_in']))
{
    redirect('./login.php');
}
// start class
$p = new Pager;

// gert member type description
if(isset($_GET['description']))
{
    $memberType = $_GET['memberType'];
    }

$max = 10; //amount of articles per page. change to what to want
$p = $_GET['p'];
if(empty($p))
{
$p = 1;
}
$limits = ($p - 1) * $max; 

$sql1="select id from members_memberType where description = '".$_GET['memberType']."'" ;
$result=mysql_query($sql1);
$row = mysql_fetch_array($result);
$memberTypeId = $row['id'];
if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];
if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])
 
//$id = "('" . implode( "','", $checkbox ) . "');" ;
$id = "('" . implode( "','", array_values($checkbox) ) . "');" ; 

$sql="UPDATE members_users SET memberTypeid = ".$memberTypeId." WHERE id in $id" ;
$result = mysql_query($sql) or die(mysql_error());
}
//view the news article!
if(isset($_GET['act']) && $_GET['act'] == "view")
{

while($r = mysql_fetch_array($sql))
{

echo "<div><p>$title</p><p>$author</p><p>$story</p></div>";
}

}else{

//view all the news articles in rows
$sql = mysql_query("SELECT * FROM vwUserMemberType where description = '".$_GET['memberType']."' or membertypeid < 2 LIMIT ".$limits.",$max") or die(mysql_error());
$result=mysql_query($sql);
//the total rows in the table
$totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM vwUserMemberType where description = '".$_GET['memberType']."' or membertypeid < 2"),0);    
//the total number of pages (calculated result), math stuff...
$totalpages = ceil($totalres / $max); 
//the table
    echo "<html>";
                echo "<head>";  
                echo "<title>View Children Records</title>";
                print '<link href="../images/admin.css" rel="stylesheet" type="text/css" media="all" />' ;     
                print '<meta http-equiv="Content-Type" content="text/html"; charset=utf-8"/>';
                print '<script type="text/javascript" src="../images/hint.js">';
                print '<table width="549" border="0" align="center" cellpadding="0" cellspacing="0">';
                print '<!--';
                print 'function un_check(){' ;
                print 'for (var i = 0; i < document.frmactive.elements.length; i++) {';
                print 'var e = document.frmactive.elements[i];';
                print "if ((e.name != 'allbox') && (e.type == 'checkbox')) {";
                print 'e.checked = document.frmactive.allbox.checked;';
                print '}';
                print '}';
                print '}';
                print '//-->';
                print '</script>';
                print '</head>';
                print '<body link="white" vlink="white"  <font color="white"/>';
                print '<table align="center">';
                print '<tr>';
                print '<td align="center" width="100%" height="58"><img src="../images/header_logo.gif" width="252" height="58" border="0"  /></a></td>';
                print '</tr>';
                print '</table>';
                print '<tr>';
                print '<td height="2"><img src="../images/grey_pixel.gif" width="100%" align="center" height="2" /></td>';
                print '</tr>';
                echo '<table border="0" align="center" cellpadding="10" >';
                echo '<tr>';
                echo '<td><h1> <font color="#FFFFFF">View Children Records</font></h1></td> ';
            //    echo "<h1>View Children Records</h1>";
            //    echo '</td>';
                echo '</tr>';
                echo '</table>'; 
echo '<form name="frmactive" method="post" action="">';
echo '<table border="1" align="center" cellpadding="10" >';
echo '<tr align="right"><th> <font color="white"/> First Name</th> <th><font color="white"/> Last Name</th><th><font color="white"/> Date of birth</th><th></th> <th></th></tr>';
while($r = mysql_fetch_array($sql))
{
//echo "<td><a href='viewChildren.php?act=view&id=$id'>$title</a></td><td>$author</td>";

        $ID = $r['id'];
    $description=$r['description'];
    $FrstName=$r['firstname'];
    $cSurname=$r['lastname'];
    $membertypeid=$r['membertypeid'];
    
 
    echo '<tr  align="right">';
    echo '<td> <font color="white"/>' . $membertypeid . '</td>';
    echo '<td> <font color="white"/>  ' . $description . '</td>';
    echo '<td> <font color="white"/> ' . $FrstName . '</td>';
    echo '<td> <font color="white"/> ' . $cSurname . '</td>';
    echo '<td align="center" width="22%" class="style2"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $ID; ?>"></td>';

    echo '<td>  <font color="white"/> <a href="change_form.php?id=' . $ID . '">Edit</a></td>';
   // echo '<td>  <font color="white"/> <a href="editChild.php?id=' . $ID . '">Edit</a></td>';
    echo '<td>  <font color="white"/> <a href="delete_form.php?id=' . $ID . '">Delete</a></td>';
                               echo "</tr>";
                    //           $i++;
                               }
                     // close table>
                     for($i = 1; $i <= $totalpages; $i++){ 
                     echo "<tr>";
                     echo '<td border="1" align="right">';
                     echo "<a href='userlistScratch.php?memberType=$description&p=$i' align='right'>Page   $i   </a>|";    
                     echo "</td>";
                     echo "</tr>";
                     }


//<table align="right" width="50%">
echo '<tr align="right">';
echo '<td align="center"><input name="activate" type="submit" id="activate" value="Assign to  ' . $_GET['memberType'] . ' "</td>';
echo '</tr>';
//</table>
                               echo "</table>";
echo '</form>';
}
//close up the table
//echo "</tr></table>";


?>

       <table border="0" align="center" cellpadding="10" >
                <td><a href="./index.php" class="style2">Return to Admin Panel</a>
                </td>
                </tr>
       </table>
                
        </body>
</html>
</html>

Glad to hear its working now