0

I have a dog show result page for adding shows. It adds fine but if you look at the bottom of the form:

<div class="form-group">
        <label for="dog_name">1st Dog Name</label>
        <input type="text" class="form-control" name="dog_name">
    </div>

    <div class="form-group">
        <input type="hidden" class="form-control" name="resultIDD" value="1">
    </div>

    <div class="form-group">
        <label for="dog_name">2st Dog Name</label>
        <input type="text" class="form-control" name="dog_name">
    </div>

    <div class="form-group">
        <input type="hidden" class="form-control" name="resultIDD" value="2">
    </div>

I am trying to insert into dog_name and RresultIDD rows but it only insert one, how can I get it to do lots more?

Here is code:

<?php

   if(isset($_POST['create_show'])) {
            //Insert Judges
            $show_title        = escape($_POST['show_title']);
            $show_user         = escape($_POST['show_user']);
            $show_category_id  = escape($_POST['show_category_id']);
            $show_status       = escape($_POST['show_status']);
           // $show_image        = escape($_FILES['show_image']['name']);
            //$show_image_temp   = escape($_FILES['image']['tmp_name']);
            $show_tags         = escape($_POST['show_tags']);
            $show_content      = escape($_POST['show_content']);
            //$show_date         = escape(date('d-m-y'));
            //INSERT Judges
            $judge_affix         = escape($_POST['judge_affix']);
            $judge_name         = escape($_POST['judge_name']);
            $judge_show         = escape($_POST['show_idj']);
            //Insert Dogs
            $dog_name         = escape($_POST['dog_name']);
            $resultIDD         = escape($_POST['resultIDD']);
            //Insert Into Results
            $class_name         = escape($_POST['class_name']);
            $placement         = escape($_POST['placement']);
            $award         = escape($_POST['award']);

        //move_uploaded_file($show_image_temp, "../images/$show_image" );

//Insert Shows 
 $query = "INSERT INTO shows (show_category_id, show_title, show_user, show_content, show_tags, show_status) VALUES ('$show_category_id','$show_title','$show_user','$show_content','$show_tags','$show_status');";
 $query .= "INSERT INTO judges (judge_affix, judge_name) VALUES ('$judge_affix','$judge_name');";
 $query .= "INSERT INTO dogs (dog_name, resultIDD) VALUES ('$dog_name','$resultIDD');";  
 $query .= "INSERT INTO result(class_name, placement,) VALUES ('$class_name','$placement')"; 


      $create_show_query = mysqli_multi_query($connection, $query);  

      confirmQuery($create_show_query);

      $the_show_id = mysqli_insert_id($connection);


      echo "<p class='bg-success'>Show Created. <a href='../show.php?s_id={$the_show_id}'>View Post </a> or <a href='shows.php'>Edit More Shows</a></p>";

   }

?>

    <form action="" method="post" enctype="multipart/form-data">


        <div class="form-group">
            <label for="show_title">Show Title</label>
            <input type="text" class="form-control" name="show_title">
        </div>

        <div class="form-group">
            <label for="category">Category</label>
            <select name="show_category" id="">

<?php

        $query = "SELECT * FROM categories";
        $select_categories = mysqli_query($connection,$query);

        confirmQuery($select_categories);


        while($row = mysqli_fetch_assoc($select_categories )) {
        $cat_id = $row['cat_id'];
        $cat_title = $row['cat_title'];


            echo "<option value='$cat_id'>{$cat_title}</option>";

        }
?>

       </select>

        </div>


        <div class="form-group">
            <label for="users">Users</label>
            <select name="post_user" id="">

<?php

        $users_query = "SELECT * FROM users";
        $select_users = mysqli_query($connection,$users_query);

        confirmQuery($select_users);


        while($row = mysqli_fetch_assoc($select_users)) {
        $user_id = $row['user_id'];
        $username = $row['username'];


            echo "<option value='{$username}'>{$username}</option>";

        }

?>

       </select>

        </div>

        <!-- <div class="form-group">
         <label for="title">Post Author</label>
          <input type="text" class="form-control" name="author">
      </div> -->

        <div class="form-group">
            <select name="show_status" id="">
             <option value="draft">Show Status</option>
             <option value="published">Published</option>
             <option value="draft">Draft</option>
         </select>
        </div>

        <div class="form-group">
            <label for="show_tags">Show Tags</label>
            <input type="text" class="form-control" name="show_tags">
        </div>

        <div class="form-group">
            <label for="judge_name">Show Tags</label>
            <input type="text" class="form-control" name="judge_name">
        </div>

        <div class="form-group">
            <label for="judge_affix">Show Tags</label>
            <input type="text" class="form-control" name="judge_affix">
        </div>

        <div class="form-group">
            <label for="show_content">Show Content</label>
            <textarea class="form-control " name="show_content" id="" cols="30" rows="5">
         </textarea>
        </div>

        <div class="form-group">
            <p>Minor Puppy Dog</p>
        </div>

        <div class="form-group">
            <label for="dog_name">1st Dog Name</label>
            <input type="text" class="form-control" name="dog_name">
        </div>

        <div class="form-group">
            <input type="hidden" class="form-control" name="resultIDD" value="1">
        </div>

        <div class="form-group">
            <label for="dog_name">2st Dog Name</label>
            <input type="text" class="form-control" name="dog_name">
        </div>

        <div class="form-group">
            <input type="hidden" class="form-control" name="resultIDD" value="2">
        </div>



        <div class="form-group">
            <input class="btn btn-primary" type="submit" name="create_show" value="Publish Show">
        </div>


    </form>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)*** Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! [Don't believe it?](http://stackoverflow.com/q/38297105/1011527) – Jay Blanchard Oct 26 '16 at 13:47
  • 2
    Didn't you already post something similar earlier? http://stackoverflow.com/q/40261851/ and accepted an answer. Unless this is completely different. – Funk Forty Niner Oct 26 '16 at 13:48
  • No this is not same question. I asked how to get the multi query to work. This time I am querying how to insert into the same row multiple times in a form – gary falkland Oct 26 '16 at 13:55
  • Are you asking about the HTML part? If so, each item needs to be part of an array. For example `` Any time you use names they have to be unique or part of an array. – Jay Blanchard Oct 26 '16 at 13:58
  • yes the html part is my problem at present it only insert one record for 'dog_name and one for 'resultIDD' – gary falkland Oct 26 '16 at 13:59
  • Because you have duplicate names it will almost always take the very last one entered. When you post, there is only one of each item. – Jay Blanchard Oct 26 '16 at 14:06
  • so best way around this is to make a array? – gary falkland Oct 26 '16 at 14:08
  • Could someone please give me an example of my code working with the array edited into it? – gary falkland Oct 26 '16 at 15:38

0 Answers0