Postingan lainnya
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
A PHP Error was encountered, A Database Error Occurred
My Models: models: Stock_m.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Stock_m extends CI_Model {
public function add_stock_in($post)
{
$params = [
'item_id' => $post['item_id'],
'type' => ['in'],
'detail' => $post['detail'],
'supplier_id' => $post['supplier'] == '' ? null : $post['supplier'],
'qty' => $post['qty'],
'date' => $post['date'],
'user_id' => $this->session->userdata('userid'),
];
$this->db->insert('t_stock', $params);
}
}
My controllers: controllerts/Stock.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Stock extends CI_Controller {
function __construct()
{
parent::__construct();
check_not_login();
check_admin();
$this->load->model(['item_m', 'supplier_m', 'stock_m']);
}
public function stock_in_data() {
$this->template->load('template', 'transaction/stock_in/stock_in_data');
}
public function stock_in_add() {
$item = $this->item_m->get()->result();
$supplier = $this->supplier_m->get()->result();
$data = ['item' => $item, 'supplier' => $supplier];
$this->template->load('template', 'transaction/stock_in/stock_in_form', $data);
}
public function process() {
if(isset($_POST['in_add'])) {
$post = $this->input->post(null, TRUE);
$this->stock_m->add_stock_in($post);
$this->item_m->update_stock_in($post);
if($this->db->affected_rows() > 0) {
$this->session->set_flashdata('success', 'Data Stock-In berhasil disimpan');
}
redirect('stock/in');
}
}
}
My view: transaction/stock_in/stock_in_form.php
<section class="content-header">
<h1>Stock In
<small>Barang Masuk / Pembelian</small>
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i></a></li>
<li>Transaction</li>
<li><a href="#"></a></li>
<li class="active">Stock In</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="box">
<div class="box-header">
<h3 class="box-title">Add Stock In</h3>
<div class="pull-right">
<a href="<?=site_url('stock/in')?>" class="btn btn-warning btn-flat">
<i class="fa fa-undo"></i> Back
</a>
</div>
</div>
<div class="box-body">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<form action="<?=site_url('stock/process')?>" method="post">
<div class="form-group">
<label>Date *</label>
<input type="date" name="date" value="<?=date('Y-m-d')?>" class="form-control" required>
</div>
<div>
<label for="barcode">Barcode *</label>
</div>
<div class="form-group input-group">
<input type="hidden" name="item_id" id="item_id">
<input type="text" name="barcode" id="barcode" class="form-control" required autofocus>
<span class="input-group-btn">
<button type="button" class="btn btn-info btn-flat" data-toggle="modal" data-target="#modal-item">
<i class="fa fa-search"></i>
</button>
</span>
</div>
<div class="form-group">
<label>Item Name *</label>
<input type="text" name="item_name" id="item_name" class="form-control" readonly>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-8">
<label for="unit_name">Item Unit</label>
<input type="text" name="unit_name" id="unit_name" value="-" class="form-control" readonly>
</div>
<div class="col-md-4">
<label for="stock">Initial Stock</label>
<input type="text" name="stock" id="stock" value="-" class="form-control" readonly>
</div>
</div>
</div>
<div class="form-group">
<label>Detail *</label>
<input type="text" name="detail" class="form-control" placeholder="Tambahan / etc" required>
</div>
<div class="form-group">
<label>Supplier</label>
<select name="supplier" class="form-control">
<option value="">- Pilih -</option>
<?php foreach($supplier as $i =>$data) {
echo '<option value="'.$data->supplier_id.'">'.$data->name.'</option>';
} ?>
</select>
</div>
<div class="form-group">
<label>Qty *</label>
<input type="number" name="qty" class="form-control" required>
</div>
<div class="form-group">
<button type="submit" name="in_add" class="btn btn-success btn-flat">
<i class="fa fa-paper-plane"></i> Save
</button>
<button type="Reset" class="btn btn-flat">Reset</button>
</div>
</form>
</div>
</div>
</div>
</div>
</section>
<div class="modal fade" id="modal-item">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data.dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Select Product Item</h4>
</div>
<div class="modal-body table-responsive">
<table class="table table-bordered table-striped" id="table1">
<thead>
<tr>
<th>Barcode</th>
<th>Name</th>
<th>Unit</th>
<th>Price</th>
<th>Stock</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach($item as $i => $data) { ?>
<tr>
<td><?=$data->barcode?></td>
<td><?=$data->name?></td>
<td><?=$data->unit_name?></td>
<td class="text-right"><?=indo_currency($data->price)?></td>
<td class="text-right"><?=$data->stock?></td>
<td class="text-right">
<button class="btn btn-xs btn-info" id="select"
data-id="<?=$data->item_id?>"
data-barcode="<?=$data->barcode?>"
data-name="<?=$data->name?>"
data-unit="<?=$data->unit_name?>"
data-stock="<?=$data->stock?>">
<i class="fa fa-check"></i> Select
</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$(document).on('click', '#select', function(){
var item_id = $(this).data('id');
var barcode = $(this).data('barcode');
var name = $(this).data('name');
var unit_name = $(this).data('unit');
var stock = $(this).data('stock');
$('#item_id').val(item_id);
$('#barcode').val(barcode);
$('#item_name').val(name);
$('#unit_name').val(unit_name);
$('#stock').val(stock);
$('#model-item').modal('hide');
})
})
</script>
Tolong bantu saya memperbaiki error ini para mastah
3 Jawaban:
<div>Sorry.<br><br>Error nya seperti ini</div><pre> <strong>A PHP Error was encountered</strong>
Severity: Notice
Message: Array to string conversion
Filename: database/DB_driver.php
Line Number: 1484
Backtrace:
File: C:\xampp\htdocs\sikan_v2\application\models\Stock_m.php Line: 17 Function: insert
File: C:\xampp\htdocs\sikan_v2\application\controllers\Stock.php Line: 26 Function: add_stock_in
File: C:\xampp\htdocs\sikan_v2\index.php Line: 315 Function: require_once <br><h1>A Database Error Occurred</h1> Error Number: 1054
Unknown column 'Array' in 'field list'
INSERT INTO t_stock
(item_id
, type
, detail
, supplier_id
, qty
, date
, user_id
) VALUES ('10', Array, 'aasa', '15', '1', '2022-12-26', '1')
Filename: C:/xampp/htdocs/sikan_v2/system/database/DB_driver.php
Line Number: 692 <br></pre>
<div>Dari errornya Array tidak diketahui<br>artinya nilai yang kamu masukkan pada kasus ini di kolom "type" harusnya string bukan array</div>
<div>type Anda ditulis oleh Anda sebagai :</div><pre>['in']</pre><div>Bagi PHP, ini adalah jenis Array. Jika type Anda adalah kolom jenis string, Anda seharusnya menulis :</div><pre>'in'</pre><div>saja di baris itu.</div>