The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert multiple from input checkbox
#1
Hy, I need some help pleasee....

I want to add users_task in table task, the user can select multiple checkboxes users from the left side in the image, It depends on who wants to help him..., is task team.
[Image: Untitled_1.jpg]
If I select 3 users to help me, to generate in my MSQL(POD), and to insert the same information to all users selectet. here is my sub task tabel
[Image: image.jpg]

how can I do that?
  Reply
#2
hwo, I have tow tabels first TASK second TASC_SUB
  Reply
#3
I'm going to be writing a class to teach people how to do this, but I can give you the basics.
So there are two tricks with this.

1. Write a query that takes the id of the task and finds all the existing info on that task...

So when you're loading the page you want
(I'm assuming the task_id is a $_Get variable in the URL)
Code:
$task_id = Input::get('id');
Code:
$tasksQ = $db->query("SELECT * FROM tasks WHERE task_id = ?",array($task_id));
Code:
$tasks = $tasksQ->results();

2. Create your form like you did, but on each checkbox, have the db check to see if that box is assigned. (I can't see your code to know how you did this. Essentially what you want to do is to pass the id (NOT task_id) into the form and whether or not you want the box to be checked.

How do you know if you want the box checked? You need to write a function that does the db query and if it should be checked, it returns checked. The input should look like...
Code:
<input type="checkbox" id="employee" name="employee[]" value='<?=$v1->id?>'
Code:
<?php checkTask($v1->id,$id); ?> ><?=$v1->fname." "; ?>
checkTask is what I called your function that queries the db and looks for what should be checked. I'll show you an example of my checkDuty function that queries a different db table....

Code:
function checkDuty($employee,$workorder){
Code:
$db = DB::getInstance();
Code:
$q=$db->query("SELECT id FROM employee_jobs WHERE employee = ? AND workorder = ?",array($employee,$workorder));
Code:
$c=$q->count();

Code:
if($c==1){
Code:
echo "checked='checked'";
Code:
}else{
Code:
return false;
Code:
}
Code:
}

Then, once the form is all done, you need to check the boxes that were checked in the form and uncheck the ones that weren't. My feeling is that it is easiest to just write every single box over again as opposed to only the ones that changed.
  Reply
#4
Hy, thanks for the reply so fast. Im sorry, but I did not expressed correctly, Sad(
I have two tables, first go perfect to add to the database, but the second I want to insert together the first table, Multiple INSERT tabels.

Ferst tabel: task

[Image: image.jpg]
[Image: image.jpg]

<pre>
Code:
If(isset($_POST['submit'])){
   // prepare sql and bind parameters
   $cine_post_task = $_POST['cine_post_task'];
    $utilizator = $_POST['utilizator'];
    $titlu = $_POST['titlu'];
    $color = $_POST['color'];
    $descriere = $_POST['descriere'];
    $data_start = $_POST['data_start'];
    $data_end = $_POST['data_end'];
    $post_data = $_POST['post_data'];
    $post_time = $_POST['post_time'];
   $q = "INSERT INTO task (cine_post_task, utilizator, titlu, color, descriere, data_start, data_end, post_data, post_time )
    VALUES (
    :cine_post_task ,
    :utilizator ,
    :titlu,
    :color ,
    :descriere ,
    :data_start ,
    :data_end ,
    :post_data ,
    :post_time
    )";
    $query = $odb->prepare($q);
    $results = $query->execute(array(
    ":cine_post_task" => $cine_post_task ,
    ":utilizator" => $utilizator ,
    ":titlu" => $titlu,
    ":color" => $color ,
    ":descriere" => $descriere ,
    ":data_start" => $data_start ,
    ":data_end" => $data_end ,
    ":post_data" => $post_data ,
    ":post_time" => $post_time
    ));
    header('Location: account.php');
}
</pre>


Form:

<pre>
Code:
<form id="demo-form2" class="form-horizontal form-label-left " action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" id="payment-form">
<br>
                    <div class="form-group">
                    
                      <label class="control-label col-md-3 col-sm-3 col-xs-12">Utilizator <span class="required"></span></label>
                      <div class="col-md-7 col-sm-7 col-xs-12">
                        <select id="utilizator" name="utilizator" class="select2_single form-control" required="required" tabindex="-1">
                          <option ></option>
                           <?php

                  foreach ($departamentCS as $permOp){
                    echo "<option value='$permOp->lname'>$permOp->lname</option>";
                  }
                  ?>
                  
                        </select>
                        
                      </div>
                    </div>
                    
                    <div class="form-group">
                      <label class="control-label col-md-3 col-sm-3 col-xs-12" for="last-name">Titlu <span class="required">*</span>
                      </label>
                      <div class="col-md-7 col-sm-7 col-xs-12">
                        <input type="text" id="titlu" name="titlu" required="required" class="form-control col-md-7 col-xs-12">
                        <input type="hidden" id="last-name" name="cine_post_task" required="required" value="<?=ucfirst($user->data()->lname)?>" class="form-control col-md-7 col-xs-12">
                        <input name="post_time" id='time' type="hidden" value="" />
                        <input name="post_data" id='' type="hidden" value="<?php echo date("d/m/Y");?>" />
                    
<script>

    function startTime() {
    var today=new Date();
    var h=today.getHours();
    var m=today.getMinutes();
    var s=today.getSeconds();
    h = checkTime(h);
    m = checkTime(m);
    s= checkTime(s);
    document.getElementById('time').value = h+":"+m+":"+s;
    var t = setTimeout(function(){startTime()},1000);
}

function checkTime(i) {
    if (i<10) {i = "0" + i} // add zero in front of numbers < 10
    return i;
}

startTime();

      </script>                      
                        

                      </div>
                    </div>

<div class="form-group">
                      <label class="control-label col-md-3 col-sm-3 col-xs-12" for="last-name">Data start <span class="required">*</span>
                      </label>
                      <div class="col-md-7 col-sm-7 col-xs-12">
                       <input type="text" name="data_start" class="form-control has-feedback-left" required="required" id="single_cal2" value="<?php echo date("d/m/Y");?>" placeholder="First Name" aria-describedby="inputSuccess2Status2">
                              <span class="fa fa-calendar-o form-control-feedback left" aria-hidden="true"></span>
                              </div>
                    </div>

<div class="form-group">
                      <label class="control-label col-md-3 col-sm-3 col-xs-12" for="last-name">Data end <span class="required">*</span>
                      </label>
                      <div class="col-md-7 col-sm-7 col-xs-12">
                       <input type="text" name="data_end" class="form-control has-feedback-left" required="required" id="single_cal3" placeholder="First Name" aria-describedby="inputSuccess2Status2">
                              <span class="fa fa-calendar-o form-control-feedback left" aria-hidden="true"></span>
                              </div>
                    </div>                    
                    
                    <div class="form-group">
                      <label class="control-label col-md-3 col-sm-3 col-xs-12">Detalii<span class="required"></span>
                      </label>
                      <div class="col-md-7 col-sm-7 col-xs-12">
                        <textarea id="message" required="required" class="form-control" name="descriere" data-parsley-trigger="keyup" data-parsley-minlength="20" data-parsley-maxlength="100" data-parsley-minlength-message="Trebui sa pui celputin 20 caractere"
                          data-parsley-validation-threshold="10"></textarea>
                      </div>
                    </div>
                    
                    <div class="form-group">
                      <label class="control-label col-md-3 col-sm-3 col-xs-12">Culoare <span class="required"></span>
                      </label>
                      <div class="col-md-7 col-sm-7 col-xs-12">
                        <select class="colorpicker-selectColor-unknown" id="color" name="color">
   <option value="#000000">Black</option>                    
  <option value="#7bd148">Green</option>
  <option value="#5484ed">Bold blue</option>
  <option value="#a4bdfc">Blue</option>
  <option value="#46d6db">Turquoise</option>
  <option value="#7ae7bf">Light green</option>
  <option value="#51b749">Bold green</option>
  <option value="#fbd75b">Yellow</option>
  <option value="#ffb878">Orange</option>
  <option value="#ff887c">Red</option>
  <option value="#dc2127">Bold red</option>
  <option value="#dbadff">Purple</option>
</select>
                      </div>
                    </div>


<div class="form-group">
  <label class="control-label col-md-3 col-sm-3 col-xs-12">Fisiere<span class="required"></span>
                      </label>
<input type="file" class="filestyle" data-icon="false">

</div>

<div class="form-group">
  <label class="control-label col-md-3 col-sm-3 col-xs-12">Securitate<span class="required"></span>
                      </label>
  <input type="checkbox" required="required"  id="checkbox1" />

</div>
</pre>

here it goes well. I want to do multiple insert


[Image: image.jpg]
Second tabel: task_list_sub

form:

<pre>
Code:
<div class="container">
    <div class="row">
        <div class="form-group">
            <div class="col-sm-12 col-md-12 col-lg-12">
                <input type="search" class="form-control" id="search" placeholder="Add your options..">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="form-group">
            <div class="searchable-container">
<?php
                    //Cycle through users
                    foreach ($departamentCS as $permOp){
                            echo "            
                <div class='items col-xs-5 col-sm-5 col-md-3 col-lg-3'>
                    <div class='info-block block-info clearfix'>
                        
                        <div data-toggle='buttons' class='btn-group bizmoduleselect'>
                            <label class='btn btn-default'>
                                <div class='bizcontent'>
                                    <input type='checkbox' name='var_id[]' autocomplete='off' value=''>
                                    <span class='glyphicon glyphicon-ok glyphicon-lg'></span>
                                    <h5>$permOp->lname</h5>
                                </div>
                            </label>
                        </div>
                    </div>
                </div>";
     } ?>            
            </div>
        </div><br>
    </div><br>
</div>
                <input type="hidden" id="utilizatorr" name="utilizatorr" value="">        
                <input type="hidden" id="titlu_sub" name="titlu_sub" value="">        
                <input type="hidden" id="time_start" name="time_start" value="">        
                <input type="hidden" id="time_end" name="time_end" value="">        
                <input type="hidden" id="colorr" name="color_sub" value="">          
            <textarea id="messageee" required="required" class="form-control" name="messageee" data-parsley-trigger="keyup" data-parsley-minlength="20" data-parsley-maxlength="100" data-parsley-minlength-message="Trebui sa pui celputin 20 caractere"
                          data-parsley-validation-threshold="10"></textarea>
        
                  
                  
                  
                  
                  </div>
</pre>


Here very well good, I get users from my DB, but I want to insert the form (task_list_sub) in the database with the same query from, task.

  Reply
#5
but your Script help me, you are the best man in coding Tongue)
  Reply
#6
waht I need how to take next ID from task tabel ?
  Reply
#7
Glad I was able to help. I'm guessing you're asking me if you insert a new row in the database, how do you know the id that you just inserted...is that the question?
  Reply
#8
yes, I have problem to insert multiple form in tu tow tabels DB, and how to take the last ID from task to insert in the second tabel task_list_sub Exmp:

task
id = 1
username = Picassoo
title = Test
post_data = 2016-12-22 12:05:00
detaliss = test form here

and in to task_list_sub I need to insert all info, to help picassoo exmp:

id = 1
task_sub_id = 1 --> ID from task
username = Razvan
title = Test
post_data = 2016-12-22 12:05:00

id = 2
task_sub_id = 1 --> ID from task
username = Laura
title = Test
post_data = 2016-12-22 12:05:00
detaliss = test form here
  Reply
#9
So when you do that first task insert do your insert query...
Code:
$task = $db->insert('task',$fields); //or however you do it.

then

Code:
$taskID = $db->lastId();
  Reply
#10
Hello, I failed to make a query for my task_list_sub. I think of another solution, we can take the next ID from task DB Tabel, +1 advance ? and post in my form task_list_sub insert ?
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)