php - Undefined Index in Checkbox -


<form method="post" action="<?php $_server['php_self']; ?>">     <table border="1" cellpadding="4">         <tr>             <th>id</th>             <th>name</th>          </tr>         <?php         include('connect.php');         $getquery = "select id,username,admin tutorial_users order id asc";         $getresult = mysql_query($getquery) or die("query not executed");         while (list($id, $username, $admin) = mysql_fetch_row($getresult)) {             ?>             <?php             $checked = ($admin == 1) ? 'checked="checked"' : '';             ?>             <tr align="center">                 <td><?php echo $id; ?></td>                 <td><?php echo $username; ?></td>                 <td><?php echo "<input type='checkbox' name='admin[]' value='$id' $checked>"; ?></td>             <?php } ?>         <tr>     </table>     <p>         <input type="submit" name="submit" value="update role">     </p> </form> <?php $updated = false; if (isset($_post['submit'])) {     $admin = $_post['admin'];     $admin = join(",", $admin);     $admin = "(" . $admin . ")";     $defaultquery = "update tutorial_users set admin=0";     $defaultresult = mysql_query($defaultquery);     $upquery = "update tutorial_users set admin=1 id in $admin";     echo $upquery;     $upresult = mysql_query($upquery);     $updated = true; } ?> 

in above code have 2 questions:

  1. lets want every check box unchecked , when press submit, gives me undefined index $admin, how can fix this?

    it working fine when i'm checking @ least 1 box , passes value post array.

  2. secondly know approach achieve result or can have other way? i'm feeling bad because if have 1000 record take lot of time update 2 queries 1 one.

result: want pretty simple checked box should have value = 1 unchecked have 0.

checkboxes not included in post data when form submitted. need call isset($_post['admin']) before try else it.

also, on side note, need @ non-deprecated mysqli functions or pdo. mysql_* functions have been deprecated , removed.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -