how to active and inactive an account using check box???

Reply

Join Date: Nov 2008
Posts: 19
Reputation: freeonlinedatin is an unknown quantity at this point 
Solved Threads: 0
freeonlinedatin's Avatar
freeonlinedatin freeonlinedatin is offline Offline
Newbie Poster

how to active and inactive an account using check box???

 
0
  #1
Dec 15th, 2008
This is my code can you expllain how the user may activate or inactivate with check box....
  1. <?php
  2. mysql_connect("localhost","root","rootwdp");
  3. mysql_select_db("rams");
  4. if(isset($_REQUEST['submit']))
  5.  
  6. {
  7. $arr=$_REQUEST['chk'];
  8. foreach($arr as $key => $value)
  9. {
  10.  
  11. $sql=mysql_query("update ram set status=1 where emp_id=$value");
  12. }
  13.  
  14. $sql1="select * from ram where status=1";
  15. $res1=mysql_query($sql1);
  16.  
  17. ?>
  18. <form action="" method="post" name="form">
  19. <table border="1"><th>Username</th><th>Empid</th><th>Designation</th><th>Check box</th>
  20. <?php
  21. while($row1=mysql_fetch_array($res1))
  22. {
  23.  
  24. ?>
  25. <tr>
  26. <td><?php echo $row1[0];?></td>
  27.  
  28.  
  29. <td align="center"><?php echo $row1[1];?></td>
  30.  
  31.  
  32. <td align="center"> <?php echo $row1[2];?> </td>
  33. <td align="center">
  34. <input type="hidden" name="chk" id="chk" value="<?php $row1[1];?>"/>
  35. <input type="checkbox" id="chk" name="chk" value="<?php $row1[1];?>" />
  36. </td>
  37.  
  38.  
  39. </tr>
  40.  
  41. <?php }
  42. } ?>
  43. </table></form>
  44.  
  45. <?php
  46. mysql_connect("localhost","root","rootwdp");
  47. mysql_select_db("rams") or die("unable to select");
  48. $query = "SELECT * FROM `ram`";
  49. $dd=mysql_query($query);
  50.  
  51. ?>
  52.  
  53.  
  54. <form action="" method="post" name="form">
  55. <table border="1"><th>Username</th><th>Empid</th><th>Designation</th><th>Check box</th>
  56. <?php
  57. while( $row=mysql_fetch_array($dd))
  58. {
  59. ?>
  60. <tr>
  61. <td><?php echo $row[0];?></td>
  62.  
  63.  
  64. <td align="center"><?php echo $row[1];?></td>
  65.  
  66.  
  67. <td align="center"> <?php echo $row[2];?> </td>
  68. <td><input type="hidden" name="chk" id="chk" value="<?php $row[1];?>"/>
  69. <input type="checkbox" id="chk" name="chk" value="<?php $row[1];?>"/></td>
  70.  
  71.  
  72. </tr>
  73.  
  74. <?php } ?>
  75. </table>
  76. <table><tr><td> <input type="submit" name="submit" value="Submit" /></td></tr></table>
  77. </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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: how to active and inactive an account using check box???

 
0
  #2
Dec 16th, 2008
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..

  1. <?php
  2. mysql_connect("localhost","root","rootwdp");
  3. mysql_select_db("rams");
  4.  
  5. if($_REQUEST['submit'] == "Activate")
  6. {
  7. $arr=$_REQUEST['chk'];
  8.  
  9. $empids = implode(",",$arr);
  10.  
  11. // This will transform your array into a string with empids separated by comma e.g. 1,2,5,7
  12.  
  13. mysql_query("update ram set status=1 where emp_id in $empids");
  14. //this will set all employee ids in one go..
  15. }
  16.  
  17. if($_REQUEST['submit'] == "Deactivate")
  18. {
  19. $arr=$_REQUEST['chk'];
  20.  
  21. $empids = implode(",",$arr);
  22.  
  23. // This will transform your array into a string with empids separated by comma e.g. 1,2,5,7
  24.  
  25. mysql_query("update ram set status=0 where emp_id in $empids");
  26. //this will set all employee ids in one go..
  27. }
  28.  
  29.  
  30.  
  31.  
  32. $query = "SELECT * FROM `ram`";
  33. $dd=mysql_query($query);
  34.  
  35. ?>
  36.  
  37.  
  38. <form action="" method="post" name="form">
  39. <table border="1"><th>Username</th><th>Empid</th><th>Designation</th><th>Check box</th>
  40. <?php
  41. while( $row=mysql_fetch_array($dd))
  42. {
  43. ?>
  44. <tr>
  45. <td><?php echo $row[0];?></td>
  46.  
  47.  
  48. <td align="center"><?php echo $row[1];?></td>
  49.  
  50.  
  51. <td align="center"> <?php echo $row[2];?> </td>
  52. <td><input type="checkbox" id="chk[]" name="chk[]" value="<?php $row[1];?>"/></td>
  53.  
  54.  
  55. </tr>
  56.  
  57. <?php } ?>
  58. </table>
  59.  
  60. <table>
  61. <tr>
  62. <td> <input type="submit" name="submit" value="Activate" /></td>
  63. <td> <input type="submit" name="submit" value="Deactivate" />
  64. </tr></table>
  65.  
  66. </form>
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC