Jump to content

Store Multiple Checkboxes in MySQL


sevendeserts

Recommended Posts

I have php script that i want it to store multiple checkboxes value in MySQL. please see this:
[img src=\"http://www.arab-x.com/uploads/Mar-06/3d6c84aba6.jpg\" border=\"0\" alt=\"IPB Image\" /]
and this my script, it shows the rows but doesnt save the values
[code]
<?php
      defined( '_VALID_LM' ) or die( 'Direct Access to this location is not allowed.' );
      global $conn;

      if(isset($save)){
      echo "Hi !";
      $p_searchx =$_POST['search'];
      foreach ($p_searchx as $p_search)
  
        $query = "insert into lm_users(p_search)values('$p_search[search]') WHERE username = 'username[]'";
        $result = mysql_query($query) or die ("query not made");

      }
?>
<table width="100%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td>
   <table width="100%" border="0" cellspacing="2" cellpadding="2">
   <tr>
    <td width="30%">Enter the user name:</td>
    <td width="40%"><input name="textfield" type="text" size="25" maxlength="25"></td>
    <td width="30%"><input type="submit" name="Submit" value="Search"></td>
  </tr>
</table>
   </td>
  </tr>
  <tr>
    <td>Editing options </td>
  </tr>
  <tr>
    <td>
   <form method="POST" action="index.php?option=fishylist&action=ucp">
   <table width="100%" border="1" cellspacing="0" cellpadding="2">
  <tr>
    <td width="3%">Del</td>
    <td colspan="2">Details</td>
    <td colspan="4">Privillages</td>
  </tr>
  <tr>
    <td> </td>
    <td width="30%">name</td>
    <td width="30%">branch</td>
    <td width="10%">Search</td>
    <td width="10%">Add</td>
    <td width="10%">Edit</td>
    <td width="10%">Delete</td>
  </tr>
     <?php              
      $rs=$conn->Execute("SELECT * FROM lm_users");
      
      if(($row_total=$rs->RecordCount()>0) && $rsa=$rs->GetArray() ) {
      $row_total=$conn->RecordCount();
      foreach($rsa as $row) {        
   ?>
  <tr>
    <td><input type="checkbox" name="checkbox[]" id="checkbox[]" value="<? //echo $rows['id']; ?>"></td>
    <td><?php echo $row['username']; ?></td>
    <td><?php echo $row['userbranch'];?></td>
    <td><input type="checkbox" name= "search[]" value="1" <?php if ($row['p_search'] == 1) {echo "checked";} ?>></td>
    <td><input type="checkbox" name= "search[]" value="1" <?php if ($row['p_add'] == 1) {echo "checked";} ?>></td>
    <td><input type="checkbox" name= "search[]" value="1" <?php if ($row['p_edit'] == 1) {echo "checked";} ?>></td>
    <td><input type="checkbox" name= "search[]" value="1" <?php if ($row['p_delete'] == 1) {echo "checked";} ?>></td>
  </tr>
     <?php } }?>
  <tr>
    <td> </td>
    <td>Pagination</td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td><input type="submit" name="save" value="Save"></td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
</table>
   </form>
   </td>
  </tr>
</table>

[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.