| | |
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 |
.htaccess alexa apache api array beginner beneath binary broadband broken cakephp checkbox class cms code convert cron curl database date display dynamic echo email emptydisplayvalue encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image images include insert ip javascript joomla key keywords limit link login mail mail() memberships menu mlm multiple multipletables mysql mysql_real_escape_string network oop open passwords paypal pdf php provider query radio random redirect remote rss script search securephp server sessions smtp source space sql strip_tags syntax system table template tutorial update upload url user validator variable video voteup web youtube





