Dear experties, I have a problem to insert checkbox value which is checked by user into multiple database..when I run this code, only one row inserted into database, but I had checked more than 3 checkbox..
Here is my code, please help me..

form.php

<form id="form" name="form" method="post" action="dbase.php?id=<?php echo $id; ?>" onSubmit="return ValidateForm()">
  <table width="591" border="1" cellspacing="0">
    <tr>
      <td colspan="2">TITLE : <?php echo $row3['dept_name']; ?> Form 1 </td>
    </tr>
    <tr>
      <td width="161">Document No</td>
      <td width="420"><label for="doc_no"></label>
      <input name="doc_no" type="text" id="doc_no" size="70" maxlength="10" /></td>
    </tr>
    <tr>
      <td>Document Name</td>
      <td><label for="doc_name"></label>
      <input name="doc_name" type="text" id="doc_name" size="70" maxlength="150" /></td>
    </tr>
    <tr>
      <td>Rev No [Mth(#)]</td>
      <td><label for="rev_no"></label>
      <input name="rev_no" type="text" id="rev_no" size="70" maxlength="15" /></td>
    </tr>
    <tr>
      <td>Issuer</td>
      <td><label for="issuer"></label>
        <select name="issuer" size="1" id="issuer">
        <?php
                    while($row1 = mysql_fetch_array($result1)) {
        ?>
        <option value="<?php echo $row1['dept_id']; ?>"><?php echo $row1['dept_name']; ?></option>
        <?php } ?>
      </select></td>
    </tr>
    <tr>
      <td valign="top">Dept Receiver</td>
      <td>

<?php
$sql="SELECT * FROM dept_receiver WHERE rcvr_id != '21'";
$result=mysql_query($sql);

echo ""; 

// run through the results from the database, generating the checkboxes 
while ($row = mysql_fetch_assoc($result)) { 
   echo "\n\t"; 
   $value = $row['rcvr_id']; //you can check the output if it doesn't work3.   
   //echo "<input id='$value' type='checkbox' name='rcvr[]' value='$value'>$value";
   //echo "<input id='{$row['rcvr_id']}' type='checkbox' name='rcvr[]' value='{$row['rcvr_id']}'>{$row['rcvr_name']}";  original code
   echo "<input id='rcvr' type='checkbox' name='rcvr[]' value='{$row['rcvr_id']}'>{$row['rcvr_name']}"; 
   echo ""; 
} 
echo "";  

?>
</td>
    </tr>
    <tr>
      <td>Document Control</td>
      <td><p>
        <label>
          <input name="pvcy" type="radio" id="pvcy_0" value="n" checked="checked" />
          All user </label>
        <label>
          <input type="radio" name="pvcy" value="y" id="pvcy_1" />
          Only for received department</label>
        <br />
      </p></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="button" id="button" value="Save" /></td>
    </tr>
  </table>
</form>

dbase.php

<?php
extract ($_POST);
include 'connection/db_connect.php';
$id = $_GET['id'];

if ($_POST) {
    $rcvr = $_POST['rcvr'];
    foreach($rcvr as $key=>$value)
        $doc_no = $_POST['doc_no'];
        $doc_name = $_POST['doc_name'];
        $rev_no = $_POST['rev_no'];
        $issuer = $_POST['issuer'];
        $private = $_POST['pvcy'];

        //$value = implode(",", $rcvr);
        $sql = "INSERT INTO list SET receiver='$value', doc_no='$doc_no', doc_name='$doc_name', rev_no='$rev_no',
                issuer='$issuer', iso_cat='2', new_info='y'";
        $result = mysql_query($sql);
}

?>

you check primary key of "list" table, it may be possible that not allowing multiple docno or revno.

You can print_r($rcvr) as well as echo $sql to debug.. If you need help, post the results here..

i want a job as php developor will u all help me

www.deshmeaaj.com

Dear all, actually before this I had used the implode (rcvr1, rcvr2,..,..) to store the value into database. But after discuss with my teams, they disagree to use this way then they suggested to store the data into multiple rows.. is it easy to update, delete or?? I need your suggestion.. before I go far with second ways.. may I know what the disadvantage in the future if I use the implode???

thx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.