The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.18 (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
#11
If multiple people are using the site at the same time, that will not be accurate. Can you pastebin your task and task_sub queries?
  Reply
#12
you have all my task and sub task query up there (December 21, 2016 at 7:06 pm)
  Reply
#13
Sorry....when you post big chunks of code on this site I lose the formatting so I have a hard time figuring out what code I am looking at. Can you post just the part you're having problems with on pastebin?
  Reply
#14
ok,

INSERT query

<pre>
Code:
// prepare sql and bind parameters
   $task_id = $_POST['task_id'];
    $task_utilizator = $_POST['task_utilizator'];
    $task_sub_descriere = $_POST['task_sub_descriere'];
    $utilizator = $_POST['utilizator'];
    $titluu = $_POST['titluu'];
    $data_post = $_POST['data_post'];
    $descriere = $_POST['descriere'];
    $status_urgent = $_POST['status_urgent'];
    $status_normal = $_POST['status_normal'];
    $status_anulare = $_POST['status_anulare'];
    $status_gata = $_POST['status_gata'];
    $time_start = $_POST['time_start'];
    $time_end = $_POST['time_end'];
   $q = "INSERT INTO task_list_sub (task_id, task_utilizator, task_sub_descriere, utilizator, titluu, data_post, descriere, status_urgent, status_normal, status_anulare, status_gata, time_start, time_end )
    VALUES (
    :task_id ,
    :task_utilizator ,
    :task_sub_descriere ,
    :utilizator ,
    :titluu,
    :data_post ,
    :descriere ,
    :status_urgent ,
    :status_normal ,
    :status_anulare ,
    :status_gata ,
    :time_start ,
    :time_end
    )";
    $query = $odb->prepare($q);
    $results = $query->execute(array(
    ":task_id" => $task_id ,
    ":task_utilizator" => $task_utilizator ,
    ":task_sub_descriere" => $task_sub_descriere ,
    ":utilizator" => $utilizator ,
    ":titluu" => $titlu,
    ":data_post" => $data_post ,
    ":descriere" => $descriere ,
    ":status_urgent" => $status_urgent ,
    ":status_normal" => $status_normal ,
    ":status_anulare" => $status_anulare ,
    ":status_gata" => $status_gata ,
    ":time_start" => $time_start ,
    ":time_end" => $time_end
    
    ));
    
    
    header('Location: account.php');
}
</pre>


and here is the form


<pre>
Code:
<form id="demo-form2" class="form-horizontal form-label-left " action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" id="payment-form">
<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='utilizator' 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="text" id="task_id" name="task_id" value="">        
                <input type="text" id="task_utilizator" name="task_utilizator" value="">        
                <input type="text" id="titluu" name="titluu" value="">        
                <input type="text" id="time_start" name="time_start" value="">        
                <input type="text" id="time_end" name="time_end" value="">        
                <input type="text" id="data_post" name="data_post" value="<?php echo date("Y-m-d H:i:s");?>">          
                <input type="text" id="colorr" name="color_sub" value="">          
            <textarea id="descriere" 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>
        
        <a href="javascript:history.go(-1)" class="btn btn-primary btn-lg" >Inapoi</a>
                        <input class='btn btn-success btn-lg' type='submit' name='submit' value='Adauga' />              
                  
                  
                  
                  </div></form>
</pre>

  Reply
#15
Ahh. I see what's going on. You're not able to use our lastid function because you're not using our db class. It's really not that hard. I see several things...

the header redirect could cause problems and give you "headers already sent" errors. That's why we have the
Code:
Redirect::to('account.php');
It tries a javascript redirect first and then only relies on the headers if it needs to.

Second, by getting the info from
Code:
$_POST
, you are missing out on the data sanitization that happens when you use
Code:
Input::get

This is your insert query reformatted with the id returned to you as
Code:
$newTaskId

http://pastebin.com/W9Uag7Gj

Note...that if you don't need all those variables, it could be as simple as this...
http://pastebin.com/ZShrgaeJ

That last version cuts out 15 lines of code and does the same thing.

Let me know if something doesn't make sense.

  Reply
#16
By the way, I love your css styling. I think if we combined my PHP with your CSS/HTML, we could do something cool!
  Reply
#17
I like your script query, everything seems to be fine now, but still can not get the ID from Task tabele and insert in to task_list_sub tabele in task_id.

and i have other problem, I want to add more users to help exmp:

Task tabel

Id 35
username Picassoo
detalis userspice

id 1
username Alexandra
detalis userspice1

id2
username Marya
detalis userspice2

etc...,

And alll the users will be insert to task_list_sub tabele.

What i need here is insert from
<input type='checkbox' name='utilizator[]' autocomplete='off' value=''>

and to take the lastID from task ID, and insert to task_list_sub tabele in task_id.

here is all your query and my form

http://pastebin.com/1Bfz20x8
  Reply
#18
hahah, I love to help you, but I need your clean userspice 5.. v to start to update my css to your form.

I update your 4.2 v to my css style if you need
  Reply
#19
I'm not 100{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d} following, but I think I'm getting the gist of what is going on.

You can put something inside the [] on your form input if you need to.

So in other words, if you have
Code:
<input type='checkbox' name='utilizator[]' autocomplete='off' value=''>

You can either put an $id or you can take that thing from my pastebin where I did the insert and then put
Code:
$db->insert('task_list_sub',$fields);
Code:
$newTaskId = $db->lastId();

You can take that newTaskId and put it in your name field
Code:
name='utilizator[<?=$newTaskId]'

Then, when you are in your form processing

Code:
if(!empty($_POST)){
Code:
foreach($_POST['utilizator'] as $key => $value) {
//You'll see that you can
Code:
dump($key);
//and
Code:
dump($value);
//and you have that information separately.
Code:
}

So, here is an example of where I use this in an online ordering system.
http://pastebin.com/sUqszW8h
On line 6 I want to make sure that the quantity is not 0 or less (if it is, I ignore it)
Then I take each row and turn it into a key->value pair
Then I go row by row and multiply my price x quantity to get the total cost
Then I check to see if that order number was already in the system
If it was, I update the order
If it was not, I insert a new one.
  Reply
#20
nice, I fix someting from your code to my query, but stil I have some problem in second query. I want insert multiple checkbox values in task_list_sub tabele.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)