| | |
how to active and inactive an account using check box???
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
This is my code can you expllain how the user may activate or inactivate with check box....
php Syntax (Toggle Plain Text)
<?php mysql_connect("localhost","root","rootwdp"); mysql_select_db("rams"); if(isset($_REQUEST['submit'])) { $arr=$_REQUEST['chk']; foreach($arr as $key => $value) { $sql=mysql_query("update ram set status=1 where emp_id=$value"); } $sql1="select * from ram where status=1"; $res1=mysql_query($sql1); ?> <form action="" method="post" name="form"> <table border="1"><th>Username</th><th>Empid</th><th>Designation</th><th>Check box</th> <?php while($row1=mysql_fetch_array($res1)) { ?> <tr> <td><?php echo $row1[0];?></td> <td align="center"><?php echo $row1[1];?></td> <td align="center"> <?php echo $row1[2];?> </td> <td align="center"> <input type="hidden" name="chk" id="chk" value="<?php $row1[1];?>"/> <input type="checkbox" id="chk" name="chk" value="<?php $row1[1];?>" /> </td> </tr> <?php } } ?> </table></form> <?php mysql_connect("localhost","root","rootwdp"); mysql_select_db("rams") or die("unable to select"); $query = "SELECT * FROM `ram`"; $dd=mysql_query($query); ?> <form action="" method="post" name="form"> <table border="1"><th>Username</th><th>Empid</th><th>Designation</th><th>Check box</th> <?php while( $row=mysql_fetch_array($dd)) { ?> <tr> <td><?php echo $row[0];?></td> <td align="center"><?php echo $row[1];?></td> <td align="center"> <?php echo $row[2];?> </td> <td><input type="hidden" name="chk" id="chk" value="<?php $row[1];?>"/> <input type="checkbox" id="chk" name="chk" value="<?php $row[1];?>"/></td> </tr> <?php } ?> </table> <table><tr><td> <input type="submit" name="submit" value="Submit" /></td></tr></table> </form>
Last edited by peter_budo; Dec 15th, 2008 at 6:23 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Hi...
Why are you giving two controls the same name..
One is checkbox and other hidden field...
Just put one control...
Use checkbox and give it name as chk[] ... Yes you read right.. Its an array.. Secondly.. give its value as user's id or name (basically the field from which you will search the user in the database..
Why are you giving two controls the same name..
One is checkbox and other hidden field...
Just put one control...
Use checkbox and give it name as chk[] ... Yes you read right.. Its an array.. Secondly.. give its value as user's id or name (basically the field from which you will search the user in the database..
php Syntax (Toggle Plain Text)
<?php mysql_connect("localhost","root","rootwdp"); mysql_select_db("rams"); if($_REQUEST['submit'] == "Activate") { $arr=$_REQUEST['chk']; $empids = implode(",",$arr); // This will transform your array into a string with empids separated by comma e.g. 1,2,5,7 mysql_query("update ram set status=1 where emp_id in $empids"); //this will set all employee ids in one go.. } if($_REQUEST['submit'] == "Deactivate") { $arr=$_REQUEST['chk']; $empids = implode(",",$arr); // This will transform your array into a string with empids separated by comma e.g. 1,2,5,7 mysql_query("update ram set status=0 where emp_id in $empids"); //this will set all employee ids in one go.. } $query = "SELECT * FROM `ram`"; $dd=mysql_query($query); ?> <form action="" method="post" name="form"> <table border="1"><th>Username</th><th>Empid</th><th>Designation</th><th>Check box</th> <?php while( $row=mysql_fetch_array($dd)) { ?> <tr> <td><?php echo $row[0];?></td> <td align="center"><?php echo $row[1];?></td> <td align="center"> <?php echo $row[2];?> </td> <td><input type="checkbox" id="chk[]" name="chk[]" value="<?php $row[1];?>"/></td> </tr> <?php } ?> </table> <table> <tr> <td> <input type="submit" name="submit" value="Activate" /></td> <td> <input type="submit" name="submit" value="Deactivate" /> </tr></table> </form>
![]() |
Other Threads in the PHP Forum
| Thread Tools | Search this Thread |
apache api array basic beginner binary body broken cakephp class cms code computing confirm cron curl customizableitems database date date/time delete display dynamic echo email error file files filter folder form forms forum function functions gc_maxlifetime global google headmethod href htaccess html iframe image include ip javascript joomla limit link list login malfunction memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php phpmysql query question random recourse recursion regex script search select seo server sessions snippet source space sql static system table thesishelp trouble tutorial update upload url variable video web webdesign xml youtube





