943,617 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2465
  • PHP RSS
Dec 15th, 2008
0

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

Expand Post »
This is my code can you expllain how the user may activate or inactivate with check box....
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
freeonlinedatin is offline Offline
19 posts
since Nov 2008
Dec 16th, 2008
0

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

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..

php Syntax (Toggle Plain Text)
  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>
Reputation Points: 11
Solved Threads: 12
Junior Poster in Training
sikka_varun is offline Offline
94 posts
since Dec 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Extract Ad Links From Adsense Ad Block
Next Thread in PHP Forum Timeline: how to get data from java page without using URL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC