Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7007229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:34:48+00:00 2026-05-27T21:34:48+00:00

Is there a way to push data to two fields in a table if

  • 0

Is there a way to push data to two fields in a table if a check box is clicked?

So in English, as a pure hypothetical I have six fields and a check box in two rows. First row, field one is name, second is address, third is email.

What I want to do is if the information is to be transferred from left to right upon posting, a person needs to check a box.

The table would have six fields.

name, address, email, name2, address2, email2.

So what would happen is that data that would post in name would also post in name2, as long as the check box is checked.

Is this possible in PHP?

Ok, well since people want a script to look at for an example, here… I figure it be easier to write up a generic script than to post what I’m working on. Sorry, thought I’d make it easier for people here.

<?php

require_once('connectvars.php');
        $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
        or die('Error connecting to MySQL server.');
$output_form = 'yes';

echo '<div id="postwrap">'
?>

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Document Test</title>
<link rel="stylesheet" type="text/css" href="CSS/postie.css" />

</head>

<body>
<div id="title">
    <h3 id="NCMR2">Document Test</h3>
</div>
<?php
//Post Data
 if (isset($_POST['submit'])) {
    $ab = mysqli_real_escape_string($dbc, trim($_POST['ab']));
    $date = mysqli_real_escape_string($dbc, trim(date('Y-m-d',strtotime ($_POST['date']))));
    $part = mysqli_real_escape_string($dbc, trim($_POST['part']));
    $rev = mysqli_real_escape_string($dbc, trim($_POST['rev']));
    $partdesc = mysqli_real_escape_string($dbc, trim($_POST['partdesc']));
    $ncmrqty = mysqli_real_escape_string($dbc, trim($_POST['ncmrqty']));
    $ab2 = mysqli_real_escape_string($dbc, trim($_POST['ab']));
    $date2 = mysqli_real_escape_string($dbc, trim(date('Y-m-d',strtotime ($_POST['date']))));
    $part2 = mysqli_real_escape_string($dbc, trim($_POST['part']));
    $rev2 = mysqli_real_escape_string($dbc, trim($_POST['rev']));
    $partdesc2 = mysqli_real_escape_string($dbc, trim($_POST['partdesc']));
    $ncmrqty2 = mysqli_real_escape_string($dbc, trim($_POST['ncmrqty']));


    $output_form = 'no';

    if (empty($ab) || empty($date) || empty($part) || empty($partdesc)){

// We know at least one of the input fields is blank 
echo '<div id="alert">';
echo 'Please fill out all of the required NCMR information.<br />';
    echo '</div>';

}
    $output_form = 'yes';

}

//Access the Database
    if (!empty($ab) && !empty($date) && !empty($pod)) {
        $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
        or die('Error connecting to MySQL server.');

    $query = "INSERT INTO ncmr (ab, date, part, rev, partdesc, ncmrqty, ab2, date2, part2, rev2, partdesc2, ncmrqty2)

    VALUES ('$ab', '$date', '$part', '$rev', '$partdesc', '$ncmrqty', '$ab2', '$date2', '$part2', '$rev2', '$partdesc2', '$ncmrqty2')";

    mysqli_query($dbc,$query)
        or die ('Data not inserted.');

            // Clear the form data
    $ab = "";
    $date = "";
    $part = "";
    $rev = "";
    $partdesc = "";
    $ncmrqty = "";
    $ab2 = "";
    $date2 = "";
    $part2 = "";
    $rev2 = "";
    $partdesc2 = "";
    $ncmrqty2 = "";


      // Confirm success with the user
    echo '<tr><td class="thank">';
    echo '<p>Thank you for adding the NCRM, the correct person will be informed.</p>';
    echo '<p><a href="post.php">&lt;&lt; Back to the form</a></p>';
        $output_form = 'no';
    echo '</td></tr>';

    mysqli_close($dbc);
}
  if ($output_form == 'yes') {
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
        echo '<fieldset>';
        //Part, Rev, Part Description, NCMR Qty
            echo '<div id="box1">';
                echo '<div id="ab"><span class="b">Added By:&nbsp;&nbsp;</span><input type="text" name="ab" value="" /></div>';
                echo '<div id="date"><span class="b">Date Filed:&nbsp;&nbsp;</span><input type="text" name="date" value="" /></div>';
                echo '<div id="part"><span class="b">Part Number:&nbsp;&nbsp;</span><input type="text" name="part" value="" /></div>';
                echo '<div id="rev"><span class="b">Part Revision:&nbsp;&nbsp;</span><input type="text" name="rev" value="" /></div>';
                echo '<div id="partdesc"><span class="b">Part Description:&nbsp;&nbsp;</span><textarea name="partdesc" rows="4" cols="22" ></textarea></div>';
                echo '<div id="ncmrqty"><span class="b">NCMR Qty:&nbsp;&nbsp;</span><input type="text" name="ncmrqty" value="" /></div>';
            echo '</div>';


            echo '<div id="box2">';
                echo '<div id="ab2"><span class="b">Added By:&nbsp;&nbsp;</span><input type="text" name="ab2" value="" /></div>';
                echo '<div id="date2"><span class="b">Date Filed:&nbsp;&nbsp;</span><input type="text" name="date2" value="" /></div>';
                echo '<div id="part2"><span class="b">Part Number:&nbsp;&nbsp;</span><input type="text" name="part2" value="" /></div>';
                echo '<div id="rev2"><span class="b">Part Revision:&nbsp;&nbsp;</span><input type="text" name="rev2" value="" /></div>';
                echo '<div id="partdesc2"><span class="b">Part Description:&nbsp;&nbsp;</span><textarea name="partdesc2" rows="4" cols="22" ></textarea></div>';
                echo '<div id="ncmrqty2"><span class="b">NCMR Qty:&nbsp;&nbsp;</span><input type="text" name="ncmrqty2" value="" /></div>';
            echo '</div>';
                    echo '<div id="button3"><input type="submit" value="Submit NCMR" name="submit" /></div>';
            echo '</div>';
    echo '</fieldset>';
echo '</form>';
    }
echo '</div>';
?>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:34:49+00:00Added an answer on May 27, 2026 at 9:34 pm

    Set a name to the checkbox, say “duplicateBox“, and have its value set to 1 when checked.

    <?php
        $name = $_POST['name'];
        $address = $_POST['address'];
        $email = $_POST['email'];
        $name2 = $_POST['name2'];
        $address2 = $_POST['address2'];
        $email2 = $_POST['email2'];
        $duplicate = $_POST['duplicateBox'];
    
    
        if($duplicate == 1)
        {
            $name2 = $name;
            $address2 = $address;
            $email2 = $email;
        }
    
        $insert = "INSERT INTO `table` (name,address,email,name2,address2,email2) VALUES ('$name','$address','$email','$name2','$address2','$email2')";
        mysql_query($insert)or die(mysql_error());
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do you know is there a way to push data to SL 4.0 client
Is there a way to simulate push notifications by pushing data to mobile safari?
Short: Is there a way to push data from the server to a logged
In PL/SQL Developer v7.1.x, is there way way to ignore large data types in
Is there any way to check whether a file is locked without using a
Is there any mechanism that I can push data into a webbrowser control from
Is there way in next piece of code to only get the first record?
is there way thats i can preselect an item when the page loads or
is there way how to get name ov event from Lambda expression like with
Is there way to better identify design pattern in source codes, esp. if you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.