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
/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 variabile
#1
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
  Reply
#2
Can you paste the entire file on pastebin so I can see it preformatted?
  Reply
#3
https://github.com/artpicassoo/pastebin/...114d}20POD
  Reply
#4
https://github.com/artpicassoo/pastebin/...ff=unified
  Reply
#5
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.

  Reply
#6
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?
  Reply
#7
I change something, but still I have some problems. I get empty rows in my DB

https://github.com/artpicassoo/pastebin/...727d0eec6b
  Reply
#8
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
  Reply
#9
Just datatime
  Reply
#10
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.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)