The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$archive_pages - Line: 2 - File: printthread.php(287) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/printthread.php(287) : eval()'d code 2 errorHandler->error
/printthread.php 287 eval
/printthread.php 117 printthread_multipage



UserSpice
INSERT variabile - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28)
+--- Forum: Documentation (https://userspice.com/forums/forumdisplay.php?fid=30)
+--- Thread: INSERT variabile (/showthread.php?tid=371)

Pages: 1 2


INSERT variabile - picassoo - 11-27-2016

Hey again, sory I needd again your help here. I have form and I need to add in DB in tow tabels. Here i trid to make the form but no luck, can you help my again pleasee.


INSERT POST SCRIPT

<pre>
Code:
//Forms posted
if (!empty($_POST)) {
  
  //Manually Add User
  if(!empty($_POST['addTask'])) {
    $cine_post_task = Input::get('cine_post_task');
      $utilizator = Input::get('utilizator');
      $titlu = Input::get('titlu');
      $color = Input::get('color');
    $descriere = Input::get('descriere');
    $data_start = Input::get('data_start');
    $data_end = Input::get('data_end');
    $post_data = Input::get('post_data');
    $post_time = Input::get('post_time');
    $descriere = Input::get('descriere');

    $form_valid=FALSE; // assume the worst
    $validation = new Validate();
    $validation->check($_POST,array(
      'cine_post_task' => array(
      'display' => '',
      'required' => false,
      'min' => 5,
      'max' => 35,
      ),
      'utilizator' => array(
      'display' => '',
      'required' => false,
      'min' => 2,
      'max' => 35,
      ),
      'titlu' => array(
      'display' => '',
      'required' => false,
      'min' => 2,
      'max' => 35,
      ),
      'color' => array(
      'display' => '',
      'required' => false,
      ),
      'descriere' => array(
      'display' => '',
      'required' => false,
      ),
      'data_start' => array(
      'display' => '',
      'required' => false,
      ),
      'data_end' => array(
      'display' => '',
      'required' => false,
      ),
      'post_data' => array(
      'display' => '',
      'required' => false,
      ),
      'post_time' => array(
      'display' => '',
      'required' => false,
      ),
    ));
      if($validation->passed()) {
        $form_valid=false;
      try {
        // echo "Trying to create user";
        $fields=array(
          'task_utilizator' => Input::get('utilizator'),
          'task_sub_descriere' => Input::get('descriere'),
        );
         $db->insert('task',$fields);
        $theNewId=$db->lastId();
        // bold($theNewId);
        $addNewTask = array('id' => $theNewId, 'task_id' => $perm);
        $db->insert('task_list_sub',$addNewTask);

        $successes[] = lang("ACCOUNT_USER_ADDED");

      } catch (Exception $e) {
        die($e->getMessage());
      }

    }
  }
}
</pre>



HERE 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">
<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="first-name" name="utilizator" class="select2_single form-control" required="required" tabindex="-1">
                          <option ></option>
                           <?php

                  foreach ($departamentCS as $permOp){
                    echo "<option value='$permOp->id'>$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="last-name" 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");?>" />
                      </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" 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>
                      <div class="modal-footer">
                        <input class='btn btn-success' type='submit' name='addTask' value='Adauga' />
                      </div>
</form>
</pre>


thank you


INSERT variabile - mudmin - 11-27-2016

Can you paste the entire file on pastebin so I can see it preformatted?


INSERT variabile - picassoo - 11-29-2016

https://github.com/artpicassoo/pastebin/blob/master/{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}7CInsert{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}20in{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}20mysqli{3bc1fe685386cc4c3ab89a3f76566d8931e181ad17f08aed9ad73b30bf28114d}20POD


INSERT variabile - picassoo - 11-29-2016

https://github.com/artpicassoo/pastebin/commit/3f4c94f5679f806df4f191e51a4a3630c349148b?diff=unified


INSERT variabile - mudmin - 11-30-2016

Ok. So help me figure out where you are stuck. Obviously without your database, I can't see everything, but I can tell you how I would start to solve it.

1. Double check that all your database columns have the right format. If one field is formatted improperly, the insert will fail.

The thing that sticks out to me is that you are dealing with dates. So, if your database is listed as datetime, look at how it is formatted. Is it something like this 2016-09-30 10:00:00 in the database if you add it manually? After you look at it, add
dnd($post_time);
right after the line...
$post_time = Input::get('post_time');
to make sure the time you're posting is in the right format. Otherwise, you need to do some date and time conversions.

2. I see you are doing multiple inserts. Are any of them working? Which one are you getting stuck on?

3. Also, feel free to comment out all your validation. I almost never add the form validation until I'm sure that the entire query works.

4. I use dnd() and die() a lot to figure out how far I made it through the process. So after an insert, I'll do die("Made it to step 3"); to figure out where things went wrong.




INSERT variabile - picassoo - 11-30-2016

Ups sory, here is my DB

-- ----------------------------
-- Table structure for
Code:
task
-- ----------------------------
DROP TABLE IF EXISTS
Code:
task
;
CREATE TABLE
Code:
task
(
Code:
id
int(11) NOT NULL AUTO_INCREMENT,
Code:
cine_post_task
varchar(255) DEFAULT NULL,
Code:
task_utilizator_ok
varchar(255) DEFAULT NULL,
Code:
utilizator
varchar(250) DEFAULT NULL,
Code:
titlu
varchar(100) DEFAULT NULL,
Code:
color
varchar(20) DEFAULT NULL,
Code:
descriere
varchar(500) DEFAULT NULL,
Code:
data_start
varchar(20) DEFAULT NULL,
Code:
data_end
varchar(20) DEFAULT NULL,
Code:
post_data
varchar(20) DEFAULT NULL,
Code:
post_time
varchar(15) DEFAULT NULL,
Code:
mdf_data
timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
Code:
mdf_username
varchar(250) DEFAULT NULL,
PRIMARY KEY (
Code:
id
)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of task
-- ----------------------------
INSERT INTO
Code:
task
VALUES ('1', null, 'Razvan', 'Razvan', 'test1', '#000000', 'sdfsdfhsdfhsdfh', '27/11/2016', '10/12/2016', null, null, '2016-11-27 21:04:21', null);
INSERT INTO
Code:
task
VALUES ('2', null, null, 'Razvan', 'test2', '#ffb878', 'dfsgdfhgsdf', '27/11/2016', '10/12/2016', null, null, '2016-11-27 21:00:48', null);
INSERT INTO
Code:
task
VALUES ('3', null, null, 'Laura Razvan', 'test3', '#ffb878', 'dfghsdfh', '27/11/2016', '10/12/2016', null, null, '2016-11-27 21:00:39', null);


do you have any other ideas about what should I do?


INSERT variabile - picassoo - 11-30-2016

I change something, but still I have some problems. I get empty rows in my DB

https://github.com/artpicassoo/pastebin/commit/e19c0c51a5713e287ac243f93daeab727d0eec6b


INSERT variabile - mudmin - 12-01-2016

I based this off of your second pastebin. It updates the database. Obviously there are some queries that weren't included in the code you sent me.

Note that if you do times and dates in varchar like you're doing, you won't be able to add and subtract them. You want to use either datetime or timestamp in the database.

http://pastebin.com/msJ6Ffez


INSERT variabile - picassoo - 12-01-2016

Just datatime


INSERT variabile - mudmin - 12-01-2016

Ok. The database dump you sent me had your date columns set as varchar. That will make it difficult for you to calculate time from the results in the db.