We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,787 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

insert value into multiple rows

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);
}

?>
4
Contributors
6
Replies
1 Day
Discussion Span
7 Months Ago
Last Updated
7
Views
HasNor
Junior Poster
101 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

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

Javvy
Junior Poster
150 posts since Feb 2011
Reputation Points: 10
Solved Threads: 31
Skill Endorsements: 2

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

www.deshmeaaj.com

harshita317
Newbie Poster
3 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

i know the php coading
i want a job as php developer

http://wwww.deshmeaaj.com

harshita317
Newbie Poster
3 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

HasNor
Junior Poster
101 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

thx

harshita317
Newbie Poster
3 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1131 seconds using 2.76MB