Jump to content

[SOLVED] PHP Insert checkbox val + textbox val


klpang

Recommended Posts

I have some dynamic checkboxes and corresponding textboxes.

 

<?php

$sqlvas = "SELECT * FROM vas ORDER BY vasname";

$resultvas = mysql_query($sqlvas);

$rowvas = mysql_fetch_array($resultvas);

?>

<TR>

<TD><?php

IF ($rowvas) {

DO { ?>

 <INPUT TYPE="checkbox" NAME="vas[]" VALUE="<?php echo $rowvas["vasID"]; ?>"><FONT CLASS="normalText"> <?php echo $rowvas["vasname"]; ?> (<?php echo $rowvas["price"]; ?>)</FONT><INPUT TYPE="text" NAME="txtDate[]" MAXLENGTH="10" SIZE="15"><BR>

<?php } while ($rowvas = mysql_fetch_array($resultvas));

}?>

 

When a user ticks a checkbox and enters data into the corresponding textbox and submits, the value of the checkbox and textbox should be inserted into the database. I can insert the checkbox values perfectly, but the textbox values have issues.

 

How to match the textbox and check has been checked and insert into database after post it to next page? Does it will involve javascript to handle it?  Please advise.

Link to comment
Share on other sites

change form patr to

<?php
            $sqlvas = "SELECT * FROM vas ORDER BY vasname";
            $resultvas = mysql_query($sqlvas);
            $rowvas = mysql_fetch_array($resultvas);
            ?>
            <TR>
               <TD><?php
               IF ($rowvas) {
               DO { ?>
                      <INPUT TYPE="checkbox" NAME="vas[]" VALUE="<?php echo $rowvas["vasID"]; ?>"><FONT CLASS="normalText"> <?php echo $rowvas["vasname"]; ?> (<?php echo $rowvas["price"]; ?>)</FONT><INPUT TYPE="text" NAME="txtDate[<?php echo $rowvas["vasID"]; ?>]" MAXLENGTH="10" SIZE="15"><BR>
            <?php } while ($rowvas = mysql_fetch_array($resultvas));
            }?>

and on submit page try

foreach($_POST['vas'] as $id){
  echo $id, ' --> ', $_POST['txtDate'][$id];
}

Link to comment
Share on other sites

Dear Sasa,

Please ignore previous reply. i already find a way to validate the txtdate and successful insert into tables individually. if need to edit, how do i know which package is has been checked by customer and the date text box and remark textarea will also will display information.

 

$sql2 = "SELECT group_concat(vas) as vas from woservice WHERE workorderID = '$workorderID'";

print $sql2;

$result2 = mysql_query($sql2) or die (mysql_error());

$row2 = mysql_fetch_array($result2);

$package=explode(",", $row2["vas"]);

 

<?php

$sqlvas = "SELECT * FROM vas ORDER BY vasname";

$resultvas = mysql_query($sqlvas);

$rowvas = mysql_fetch_array($resultvas);

?>

<TR>

<TD><?php

IF ($rowvas)

{

DO

{ ?>

 <INPUT TYPE="checkbox" NAME="vas[]" VALUE="<?php echo $rowvas["vasID"]; ?>"><FONT CLASS="normalText"> <?php echo $rowvas["vasname"]; ?> (<?php echo $rowvas["price"]; ?>)</FONT><INPUT TYPE="text" NAME="vasDate[<?php echo $rowvas["vasID"]; ?>]" MAXLENGTH="10" SIZE="15" ONBLUR=javascript:isDate(this.value);> <FONT CLASS="normalText">(dd-mm-yyyy)</FONT><BR><FONT CLASS="UserSort">Remark</FONT>  <TEXTAREA COLS="30" ROWS="3" NAME="vasremark[<?php echo $rowvas["vasID"]; ?>]"></TEXTAREA><BR>

<?php

} while ($rowvas = mysql_fetch_array($resultvas));

}?>

</TD>

</TR>

 

Thanks in advance.

 

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.