title: How to create Multi Row into database via the single post
body: <p>I am trying to making something like wordpress <code>post-new.php</code>, inside of it there is a system call Categories where all of menus category are held, inside of my page I just built like it, but my <strong>problem</strong> is when I checked multi menus options to post then it is not working, but into wordpress I just looking that there is a TABLE called relation there is all kind of post where attach with categories and there is a point when I post something and checked from categories then I see post_id=(same number) but term_taxonomy_id=(is different number) same post_id many times but term_taxonomy_id is different from one to another, and that's why wordpress can separate there post by categories, but my coding is not working of that, </p>
  
  <p>here is my codes, and my sql.</p>
  
  <pre><code>&lt;?php
  ob_start();
  require('config2.php');
  
  
  $dbcon = new MySQLi("mysql1.000webhost.com","a9042680_softbaz","asdfghjk99","a9042680_softbaz");
  
  $save_draft = $_POST['save_draft'];
  $preview = $_POST['preview'];
  $cancel = $_POST['cancel'];
  $publish = $_POST['publish'];
  
  $post_title = mysql_real_escape_string($_POST['post_title']);
  
  $post_body = mysql_real_escape_string($_POST['post_body']);
  
  $oks = $_POST['post_body'];
  
  // post_time
  // Variable for hours
  $hourdiff = "4"; // hours difference between server time and local time
  
  // time is behind the server time
  $timeadjust = ($hourdiff * 3600);
  $post_time = date("l, d F Y h:i:s a",time() + $timeadjust);
  $real_time = date("Y-m-d H:i:s",time() + $timeadjust);
  
  //ip check
  
  $http_client_ip = $_SERVER['HTTP_CLIENT_IP'];
  $http_x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR'];
  $remote_addr = $_SERVER['REMOTE_ADDR'];
  
  if (!empty($http_client_ip)) {
    $ip_address = $http_client_ip;
  } else if  (!empty($http_x_forwarded_for)) {
    $ip_address = $http_x_forwarded_for;
  } else {
    $ip_address = $remote_addr;
  }
  
  //Menu checkbox function
  
  $c_m_menu_id = $_POST['c_m_menu_id'];
  
  $c_s_menu_id = $_POST['c_s_menu_id'];
  
  $c_s_menu_id2 = $_POST['c_s_menu_id2'];
  
  
  
  //save_draft function
  
      if($save_draft) {
  
          if($post_title&amp;&amp;$post_body&amp;&amp;$post_time) {
          $insert=mysql_query("INSERT INTO post (post_title,post_body,post_time,real_time,ip_address,post_status) VALUES ('$post_title', '$post_body', '$post_time', '$real_time', '$ip_address', 'F')");
          header("Location: test4.php");
      }else{
          header("Location: 000.php");
      }
  
      }
  
  //preview function
  
  
      if($preview){
  
  
  $fp = fopen('preview.php' ,'w');
  fwrite($fp, "&lt;?php
  error_reporting(E_ERROR | E_PARSE);
  
      include 'opo.php';
       ?&gt;
  
  &lt;?php
      hera();
  ?&gt;
      $post_title;
      $oks;
  &lt;?php   
      foot();
  
  
  
  ?&gt;
  
  
  ");
          echo "&lt;script&gt;window.open(\"http://localhost/myweb/dashbord/preview.php\", '_blank');&lt;/script&gt;";
  
      }
  //cancel function
  
  //publish function
      if($publish) {
  
          if($post_title&amp;&amp;$post_body&amp;&amp;$post_time) {
          mysql_query("INSERT INTO post (post_title,post_body,post_time,real_time,ip_address,post_status) VALUES ('$post_title', '$post_body', '$post_time', '$real_time', '$ip_address', 'T')");
          mysql_query("INSERT INTO relation (m_menu_id,s_menu_id,s_menu_id2) VALUES ('$c_m_menu_id', '$c_s_menu_id', '$c_s_menu_id2')");
          header("Location: test4.php");
      }else{
          header("Location: 000.php");
      }
  
      }
  ?&gt;
  
  
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  
  &lt;!-- include jquery --&gt;
    &lt;script src="//code.jquery.com/jquery-1.9.1.min.js"&gt;&lt;/script&gt; 
  
    &lt;!-- include libraries BS3 --&gt;
    &lt;link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" /&gt;
    &lt;script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"&gt;&lt;/script&gt;
    &lt;link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" /&gt;
  
    &lt;!-- Link Value --&gt;
  
  
    &lt;script type="text/javascript"&gt;
          $(document).ready(function() {
              $('#myInputText').keyup(function() {
               $('#myOutputText').val($(this).val().toLowerCase().replace(/ /g, '-'));
               $('#myOutputText2').attr('placeholder',$(this).val());
               $('#myOutputText3').val($(this).val().toLowerCase().replace(/ /g, ', '));
               $('#myDIVTag').html('&lt;b&gt;' + $(this).val() + '&lt;?php echo ' - '.$_SERVER['SERVER_NAME']; ?&gt;&lt;/b&gt;');
              });
          }); 
  
  $(document).ready(function() {
              $('#myInputText2').keyup(function() {
               $('#myOutputText4').val($(this).val());
              });
          });         
      &lt;/script&gt;
  
  
    &lt;!-- include summernote --&gt;
    &lt;link rel="stylesheet" href="dist/summernote.css"&gt;
    &lt;script type="text/javascript" src="dist/summernote.js"&gt;&lt;/script&gt;
  
    &lt;script type="text/javascript"&gt;
      $(document).ready(function() {
        $('.summernote').summernote({
          height: 200,
          tabsize: 2,
          codemirror: {
            theme: 'monokai'
          }
        });
      });
    &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post" enctype="multipart/form-data"&gt;
  &lt;table width="100%" border="1" cellpadding="5" cellspacing="7"&gt;
    &lt;tr&gt;
      &lt;td width="73%"&gt;&lt;h2&gt;Add New Post&lt;/h2&gt;
  
          &lt;p&gt;
            &lt;label&gt;
              &lt;input id="myInputText" type="text" name="post_title" size="79" placeholder="Enter title here" /&gt;
            &lt;/label&gt;
          &lt;/p&gt;
          &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;?php echo $_SERVER['SERVER_NAME'].'/'; ?&gt;&lt;input id="myOutputText" type="text" name="outputBox" /&gt;&lt;/p&gt;
          &lt;p&gt;
            &lt;label&gt;
              &lt;textarea id="myInputText2" name="post_body" class="summernote"&gt;&lt;/textarea&gt;
            &lt;/label&gt;
          &lt;/p&gt;
  
      &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
      &lt;td width="27%" valign="top"&gt;&lt;h2&gt;Publish&lt;/h2&gt;
  
          &lt;table width="178" cellpadding="2" cellspacing="2"&gt;
            &lt;tr&gt;
              &lt;td width="101" height="33"&gt;&lt;label&gt;
                &lt;input type="submit" name="save_draft" value="Save Draft" /&gt;
              &lt;/label&gt;&lt;/td&gt;
              &lt;td width="65"&gt;&lt;label&gt;
                &lt;input type="submit" name="preview" value="Preview" /&gt;
              &lt;/label&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;label&gt;
                &lt;input type="submit" name="cancel" value="Cancel" /&gt;
              &lt;/label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;label&gt;
                &lt;input type="submit" name="publish" value="Publish" /&gt;
              &lt;/label&gt;&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/table&gt;
  
      &lt;h2&gt;Featured Image&lt;/h2&gt;
  
        &lt;label&gt;
          &lt;input type="file" name="fileField2" id="fileField2" /&gt;
        &lt;/label&gt;
  
      &lt;p&gt;&amp;nbsp;&lt;/p&gt;
      &lt;h2&gt;Categories&lt;/h2&gt;
      &lt;p&gt;
  
      &lt;?php
  $res=$dbcon-&gt;query("SELECT * FROM main_menu");
  while($row=$res-&gt;fetch_array())
  {
      ?&gt;
     &lt;li&gt;&lt;input type="checkbox" name="c_m_menu_id" value="&lt;?php echo $row['m_menu_id']; ?&gt;"&gt;&lt;?php echo $row['m_menu_name']; ?&gt;  &lt;!-- 1st --&gt;
     &lt;?php
      $res_pro=$dbcon-&gt;query("SELECT * FROM sub_menu WHERE m_menu_id=".$row['m_menu_id']);
      ?&gt;
        &lt;ul&gt;              
          &lt;?php  
          while($pro_row=$res_pro-&gt;fetch_array())
          {
              ?&gt;&lt;li&gt;&lt;input type="checkbox" name="c_s_menu_id" value="&lt;?php echo $pro_row['s_menu_id']; ?&gt;"&gt;&lt;?php echo $pro_row['s_menu_name']; ?&gt; &lt;!-- 2nd --&gt;
  
              &lt;?php
                  $res_pror=$dbcon-&gt;query("SELECT * FROM sube_menu WHERE s_menu_id=".$pro_row['s_menu_id']);
              ?&gt;
  
              &lt;ul&gt;
                  &lt;?php  
          while($pro_rowe=$res_pror-&gt;fetch_array())
          { ?&gt;    
                 &lt;li&gt;&lt;input type="checkbox" name="c_s_menu_id2" value="&lt;?php echo $pro_rowe['s_menu_id2']; ?&gt;"&gt;&lt;?php echo $pro_rowe['s_menu_name2']; ?&gt;&lt;/li&gt; &lt;!-- 3rd --&gt;
          &lt;?php } ?&gt;
              &lt;/ul&gt;
               &lt;/li&gt;
              &lt;?php
          }
          ?&gt;
      &lt;/ul&gt;
     &lt;/li&gt;
     &lt;?php
  }
  ?&gt;
  
  
  
  
  
      &lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;h2&gt;SEO Tools&lt;/h2&gt;
      &lt;p&gt;Snippet Preview: &lt;a href="#" id="myDIVTag"&gt;&lt;/a&gt;&lt;/p&gt;
      &lt;p&gt;Focus Keyword: 
        &lt;label&gt;
          &lt;input name="post_seo_keyword" type="text" id="myOutputText3" size="79" /&gt;
        &lt;/label&gt;
      &lt;/p&gt;
      &lt;p&gt;SEO Title: 
        &lt;label&gt;
          &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;input name="post_seo_title" type="text" id="myOutputText2" size="79" /&gt;
        &lt;/label&gt;
      &lt;/p&gt;
      &lt;p&gt;Meta description: 
        &lt;label&gt;
          &amp;nbsp;&amp;nbsp;&lt;textarea name="post_seo_description" id="myOutputText4" cols="80" rows="5"&gt;&lt;/textarea&gt;
        &lt;/label&gt;
      &lt;/p&gt;&lt;/td&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <blockquote>
    <p>SQL:</p>
  </blockquote>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `relation` (
    `posted_id` int(11) unsigned NOT NULL DEFAULT '0',
    `m_menu_id` int(11) unsigned NOT NULL DEFAULT '0',
    `s_menu_id` int(11) unsigned NOT NULL DEFAULT '0',
    `s_menu_id2` int(11) unsigned NOT NULL DEFAULT '0'
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  
  --
  -- Dumping data for table `relation`
  --
  
  INSERT INTO `relation` (`posted_id`, `m_menu_id`, `s_menu_id`, `s_menu_id2`) VALUES
  (0, 0, 0, 0),
  (0, 0, 0, 4),
  (0, 0, 13, 4),
  (0, 8, 0, 0),
  (0, 8, 12, 2),
  (0, 8, 13, 3),
  (0, 8, 13, 4),
  (0, 9, 13, 3),
  (0, 9, 13, 4);
  
  --
  -- Indexes for dumped tables
  --
  
  --
  -- Indexes for table `relation`
  --
  ALTER TABLE `relation`
    ADD PRIMARY KEY (`posted_id`,`m_menu_id`,`s_menu_id`,`s_menu_id2`);
  </code></pre>
  
  <p>Please help me and give me solution. and here is my demo testing sites where I testing for if you want to see it so please go to this link: <a href="http://softbazz.net63.net/myweb/dashbord/test4.php" rel="nofollow">softbazz.net63.net/myweb/dashbord/test4.php</a></p>