0

why i'm having this kind of error? i'm trying to develop a restaurant system and my framework is codeigniter, in this module in adding a product everthing was running fine i do not have an error but whenenever i try to insert a data from the database i'm having an php error.

A PHP Error was encountered
Severity: 8192

Message: trim(): Passing null to parameter #1 ($string) of type string is deprecated

Filename: libraries/Form_validation.php

Line Number: 1059

Backtrace:

File: C:\xampp\htdocs\Group6_Caps\application\controllers\Products.php
Line: 191
Function: run

my input field was something like this enter image description here

and whenever i try to entry a data entry it is giving me a php error this is my controller with line 178-220

public function create()
{
    if(!in_array('createProduct', $this->permission)) {
        redirect('dashboard', 'refresh');
    }

    $this->form_validation->set_rules('product_name', 'Product name', 'trim|required');
    $this->form_validation->set_rules('srp', 'SRP', 'trim|required|numeric');
    $this->form_validation->set_rules('cost', 'Cost', 'trim|required|numeric');
    $this->form_validation->set_rules('active', 'Active', 'trim|required');

    

    if ($this->form_validation->run() == TRUE) {

        $data = array(
            'name' => $this->input->post('product_name'),
            'srp' => $this->input->post('srp'),
            'cost' => $this->input->post('cost'),
            'description' => $this->input->post('description'),
            'sub_category_id' => json_encode($this->input->post('sub_category')),

            'active' => $this->input->post('active'),
        );

        $create = $this->model_products->create($data);
        if($create == true) {
            $this->session->set_flashdata('success', 'Successfully created');
            redirect('products/', 'refresh');
        }
        else {
            $this->session->set_flashdata('errors', 'Error occurred!!');
            redirect('products/create', 'refresh');
        }
    }
    else {
       
        $this->data['sub_category'] = $this->model_subcat->getActiveSubCategory();   


        $this->render_template('products/create', $this->data);
    }   
}

my index was something like this

         <div class="form-group">
              <label for="product_name">Product name:</label>
              <input type="text" class="form-control" id="product_name" name="product_name" placeholder="Enter product name" autocomplete="off" value="<?php echo $this->input->post('product_name') ?>" />
            </div>



            <div class="form-group">
              <label for="description">Description:</label>
              <textarea type="text" class="form-control" id="description" name="description" placeholder="Enter 
              description" autocomplete="off">
              <?php echo $this->input->post('description') ?>
              </textarea>
            </div>

            <div class="form-group">
              <label for="sub_category">Category:</label>
              <select class="form-control select_group" id="sub_category_1" name="sub_category[]" onchange="getSubCategoryData(1)">
                <option value=""></option>
                <?php foreach ($sub_category as $k => $v): ?>
                  <option value="<?php echo $v['id'] ?>"><?php echo $v['name'] ?></option>
                <?php endforeach ?>
              </select>
            </div>


            <div class="form-group">
              <label for="cost">Cost:</label>
              <input type="text" class="form-control" id="cost" name="cost" placeholder="Enter cost" autocomplete="off" onkeyup="getSRP(1)" value="<?php echo $this->input->post('cost') ?>"/>
            </div>
            <div class="form-group">
            

             <div class="form-group">
                <label for="markup">Markup:</label>
                  <input type="text" class="form-control" id="markup_1" name="markup" disabled autocomplete="off" placeholder="Markup">
                  <input type="hidden" class="form-control" id="markup_value_1" name="markup_value" autocomplete="off">
            </div>

            <div class="form-group">
                <label for="srp">SRP:</label>
                  <input type="text" class="form-control" id="srp" name="srp" disabled autocomplete="off" placeholder="SRP">
                  <input type="hidden" class="form-control" id="srp_value" name="srp_value" autocomplete="off">
            </div>

            <div class="form-group">




              <label for="store">Active:</label>
              <select class="form-control" id="active" name="active">
                <option value="1">Yes</option>
                <option value="2">No</option>
              </select>
            </div>

my database is

products

    id sub_category_id name srp description active cost

line 1059 in form_validation.php

public function required($str)
{
    return is_array($str)
        ? (empty($str) === FALSE)
        : (trim($str) !== '');
}
wloleo
  • 1,294
  • 2
  • 6
  • 15
  • It would be more useful to know where `Line Number: 1059` in the file `libraries/Form_validation.php` was in all that code – RiggsFolly Oct 25 '22 at 14:30

0 Answers0