Combining two or more insert and if isset
<p>I was wondering if it was at all possible to have two or more <strong>inserts into</strong> and <strong>if isset</strong> statements that insert into the same table on the same webpage at the same time or even better within one query.</p>

<p>I have a university project, which is asking for 2/3 sets of information to be inserted into a single db tbl at the same time. I have tried to do 2 out of the 3 queries separately but i am receiving <strong><em>"Duplicate entry '' for key 'name'"</em></strong>, which makes sense as my name column in the db is unique.</p>

<p>The 2/3 sets of information are different from one and other, 1 set is inputted information, such as name, address etc. The other two sets are based on checkbox and radio button inputs e.g if checkbox is checked insert 1 into the DB, if it is unchecked insert 2.</p>

<p>Assuming the best practice is to combine the queries into one query, I have no idea how to do that. Especially as they are two different input types. Very new! so any help would be appreciated. cheers!</p>

<p><strong>INSERT into on duplicate- (text data)</strong></p>

<pre><code>  $adm_Franchise = mysqli_real_escape_string($dbc, $_GET['Franchise']);


    if (isset($_POST['Save-details'])) {
        $id = mysqli_real_escape_string($dbc, $_POST['ID']);
        $name = mysqli_real_escape_string($dbc, $_POST['name']);
        $lname = mysqli_real_escape_string($dbc, $_POST['lname']);


    $insert = "INSERT INTO Details
  ( ID , name , lname ) 
  VALUES ( ? , ?,?) 
  ON DUPLICATE KEY 
  UPDATE ID = ?
  , name               = ?
  , lname       = ?";


        $ce = mysqli_prepare($dbc, $insert);

       //$ce = mysqli_prepare($dbc, $insert) or die(mysqli_error($dbc));

        mysqli_stmt_bind_param($ce, 'ississ', $id, $name, $lname,$id, $name, $lname );

        /* execute query */
        $execute = mysqli_stmt_execute($ce);

        if ($execute) {
            echo "&lt;script&gt; alert('Saved')&lt;/script&gt;";
        }
    } else {
        echo mysqli_error($dbc);
    }
</code></pre>

<p><strong>$_POST variables HTML</strong></p>

<p>As requested:</p>

<pre><code>&lt;form id="myform " class="Form" method="POST" action="Main_Franchise_Details.php?Franchise=&lt;?php echo $_GET['Franchise']; ?&gt;" accept-charset="utf-8"&gt;

   &lt;div class="group1"&gt;
       &lt;div class="field"&gt;
               &lt;fieldset&gt;

                    &lt;input type="text" id="name" name="name" value="" placement="Customer Name" required&gt;
                &lt;/div&gt;&lt;br&gt;

                &lt;input type="text" id="lname" name="lname" value="" placement="Customer Last Name" required&gt;

       &lt;/fieldset&gt;
</code></pre>

<p><strong>Checkbox query</strong></p>

<pre><code>&lt;input type="checkbox" name="saleItem" value="1" &lt;?php echo (isset($_GET['saleItem']) ? 'checked="checked"' : '')?&gt; /&gt;

 $is_checked = (isset($_GET['saleItem']) ? '1' : '2');

 $sql=mysqli_query($dbc,"INSERT INTO Details (active) VALUES ('" . $is_checked . "')"); 

 if (!$sql) {
    die('Invalid query: ' . mysql_error($dbc));
   }
   mysqli_close($dbc); 
</code></pre>

<p><strong>DB</strong></p>

<pre><code>CREATE TABLE `Details` (
`ID` bigint(255) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`lname` varchar(200) NOT NULL,
`active` text,
 PRIMARY KEY (`ID`),
 UNIQUE KEY `name` (`Rname`),
 UNIQUE KEY `ID` (`ID`),
 ) ENGINE=InnoDB AUTO_INCREMENT=210 DEFAULT CHARSET=outfit
</code></pre>