I'm having a problem showing an alert message after submitting a form.
I have a form for submitting a report, then after submission it will be stored in a table. What I want to happen is that after submitting a report, there will be an alert message for each new submitted report. I'm using CI as framework. Here is what I have:
View:
<div class="row-fluid">
<button type="button" class="btn btn-primary col-lg-2" data-toggle="collapse" data-target="#add_form" onclick="add_clicked()">Submit Report</button><br />
<div class="col-lg-6">
<?php
$attributes = array('class' => $class, 'id' => 'add_form', 'role' => 'form');
echo form_open('admin/report', $attributes);?>
<div class="form-group">
<input class="form-control" type="hidden" name="add_hidden" value="add-report">
</div>
<br><br>
<div class="form-group">
<?=form_input( array('id'=>'sender','class'=>'form-control' ,'name'=>'sender','type'=>'text','placeholder'=> 'Senders Name', 'value' => set_value('sender'), 'required'=> 'true') );?> <br />
<?=form_input( array('id'=>'date','class'=>'form-control date-picker','name'=>'date','type'=>'text','placeholder'=> 'Date', 'value' => set_value('date') ) );
$date = date('Y-m-d H:i:s');?><br />
<?=form_textarea( array('id'=>'subject','class'=>'form-control','name'=>'subject','type'=>'message-text','placeholder'=> 'Your Message here', 'value' => set_value('subject'), 'required'=> 'true') );?><br />
</div>
<div class="form-group">
<?=form_input( array('class'=>'btn btn-success','id'=>'add_submit','type'=>'submit','value'=>'submit')) ;?>
</div>
<?=form_close();?>
</div>
<div class="col-md-10 text-center" id="success" style="display:none">
<?php if(isset($message)) echo $message ?>
</div>
</div>
</div>
<br> <br>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th style="text-align: center">Sender</th>
<th style="text-align:center">Subject</th>
<th style="text-align:center">Date</th>
</tr>
</thead>
<tbody>
<?php
foreach ($query->result_array() as $row) {
echo '
<tr>
<td style="text-align:center">'.$row["sender"].'</td>
<td style="text-align:center">'.$row["subject"].'</td>
<td style="text-align:center">'.$row["date"].'</td>
<td> <button type="button" class="btn btn-success btn-small" data-toggle="modal" data-target="#view'.$row["sender"].'"> Read </button>
<button type="button" class="btn btn-danger btn-small" data-toggle="modal" data-target="#remove'.$row["sender"].'">delete</button></td>
</tr>
';
}
?>
This is my controller:
public function report()
{
$this->load->model('report_model', 'database');
$sql = "SELECT * FROM report";
$data['query'] = $this->database->view_report($sql);
if ($this->input->post('add_hidden')) {
$this->form_validation->set_rules('sender', 'sender', 'required');
$this->form_validation->set_rules('subject', 'subject', 'required');
$this->form_validation->set_rules('date', 'date');
$this->form_validation->set_error_delimiters('<div class="has-error" style="color: #FF0000">', '</div>');
if ($this->form_validation->run() == TRUE) {
//Setting values for table columns
$data = array(
'sender' => $this->input->post('sender'),
'subject' => $this->input->post('subject'),
'date' => $this->input->post('date'),
);
//Transfering data to Model
$q = $this->database->add_report($data);
$data['query'] = $this->database->view_report($sql);
if ($q) {
$data['message'] = '<h3> Your report has successfully submitted!</h3>';
$data['success'] = '';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
} else {
$data['message'] = '<h3> Report submission unsuccessful!</h3>';
$data['success'] = '';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
}
}
else {
$data['message'] = '';
$data['success'] = 'none';
$data['class'] = '';
$this->load->view('report_view', $data);
}
}
else if ($this->input->post('del_hidden')) {
$from = $this->input->post('del_sender');
$subject = $this->input->post('del_subject');
$date = $this->input->post('del_date');
$qry = "DELETE FROM report WHERE sender = '$from'";
$q = $this->database->delete_report($qry);
$sql = "SELECT * FROM report";
$data['query'] = $this->database->view_report($sql);
if ($q) {
$data['message'] = '<h3> "' . $subject . '"message deleted from database!!</h3>';
$data['success'] = '';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
}
} else {
$data['success'] = 'none';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
}
}`
Actually you are displaying the message in view ; this part of your code is sufficient for that.
<div class="col-md-10 text-center" id="success" style="display:none">
<?php if(isset($message)) echo $message ?>
</div>
But the div has style display:none so it will not be displayed. So change it to
<?php if(isset($message))
{
?>
<div class="col-md-10 text-center" id="success">
<?php echo $message ?>
</div>
<?php
}
?>
if you want an alert message then you can change it to
<?php if(isset($message))
{
?>
<script>
alert('<?php echo $message ?>');
</script>
<?php
}
?>
If it is an javascript alert, search for the alert expression with the alerted message, put an . And use console.log()...
Related
my Controllers
public function uploadexcel()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'xlsx|xls';
$config['file_name'] = 'doc' . time();
$this->load->library('upload', $config);
if ($this->upload->do_upload('importexcel')) {
$file = $this->upload->data();
$reader = ReaderEntityFactory::createXLSXReader();
$reader->open('uploads/' . $file['file_name']);
foreach ($reader->getSheetIterator() as $sheet) {
$numRow = 1;
foreach ($sheet->getRowIterator() as $row) {
if ($numRow > 1) {
$datareceiving = array(
'lot_number' =>$this->m_receiving->joinMasterpartBarcode()."/" . $this->m_receiving->bln() . "/" . $this->m_receiving->tgl() . "/" . $this->m_receiving->getSerialNumber(),
'upload_id' => $this->m_receiving->get_no_upload_id(),
'number_part' => $row->getCellAtIndex(0),
'description' => $row->getCellAtIndex(1),
'shift' => $row->getCellAtIndex(2),
'date_production' => $row->getCellAtIndex(3),
'date_receive' => $row->getCellAtIndex(4),
'qty_transfer' => $row->getCellAtIndex(5),
'pic' => $row->getCellAtIndex(6),
'txndate' => $this->m_receiving->today(),
);
$this->m_receiving->import_data($datareceiving);
}
$numRow++;
}
$reader->close();
unlink('uploads/' . $file['file_name']);
$this->session->set_flashdata('success', 'Import Excel berhasil');
redirect('receiving');
}
} else {
echo "Error : " . $this->upload->display_errors();
}
}
public function exportexcel()
{
$get = $this->m_receiving->getAll();
// Validasi jumlah
$get->num_rows();
$writer = WriterEntityFactory::createXLSXWriter();
$writer->openToBrowser('Receiving.xlsx');
$header =
[
WriterEntityFactory::createCell('Part Number'),
WriterEntityFactory::createCell('Description'),
WriterEntityFactory::createCell('Shift'),
WriterEntityFactory::createCell('Date Production'),
WriterEntityFactory::createCell('Date Receive'),
WriterEntityFactory::createCell('Qty Transfer'),
WriterEntityFactory::createCell('Customer'),
WriterEntityFactory::createCell('PIC'),
WriterEntityFactory::createCell('Txndate'),
WriterEntityFactory::createCell('Userid'),
];
$singleRow = WriterEntityFactory::createROW($header);
$writer->addRow($singleRow);
$data = array();
// looping pembacaan Data
foreach ($get->result() as $key) {
$data_assetdata = array(
WriterEntityFactory::createCell($key->part_number),
WriterEntityFactory::createCell($key->description),
WriterEntityFactory::createCell($key->shift),
WriterEntityFactory::createCell($key->date_production),
WriterEntityFactory::createCell($key->date_receive),
WriterEntityFactory::createCell($key->qty_transfer),
WriterEntityFactory::createCell($key->id_customer),
WriterEntityFactory::createCell($key->pic),
WriterEntityFactory::createCell($key->txndate),
WriterEntityFactory::createCell($key->userid),
);
array_push($data, WriterEntityFactory::createRow($data_assetdata));
}
$writer->addRows($data);
$writer->close();
}
and this my Model
public function lihat()
{
$query = $this->db->get($this->_table);
return $query->result();
}
public function jumlah()
{
$query = $this->db->get($this->_table);
return $query->num_rows();
}
public function lihat_id($receive_id)
{
$query = $this->db->get_where($this->_table, ['receive_id' => $receive_id]);
return $query->row();
}
public function ubah($data, $receive_id)
{
$query = $this->db->set($data);
$query = $this->db->where(['receive_id' => $receive_id]);
$query = $this->db->update($this->_table);
return $query;
}
public function tambah($data)
{
return $this->db->insert($this->_table, $data);
}
public function hapus($receive_id)
{
return $this->db->delete($this->_table, ['receive_id' => $receive_id]);
}
public function getAll()
{
$this->db->from('receiving');
return $this->db->get();
}
function get_no_upload_id()
{
$q = $this->db->query("SELECT MAX(RIGHT(upload_id,2)) AS kd_max FROM receiving WHERE DATE(txndate)=CURDATE()");
$char = "-";
$kd = "";
if ($q->num_rows() > 0) {
foreach ($q->result() as $k) {
$tmp = ((int)$k->kd_max) + 1;
$kd = $char . sprintf("%02s", $tmp);
}
} else {
$kd = "1";
}
date_default_timezone_set('Asia/Jakarta');
return date('Ymd') . $kd;
}
function getSerialNumber()
{
$this->db->select('RIGHT(receiving.receive_id,5) as kode', false);
$this->db->order_by('receive_id', 'DESC');
$this->db->limit(1);
$query = $this->db->get('receiving');
if ($query->num_rows() <> 0) {
$data = $query->row();
$kode = intval($data->kode) + 1;
} else {
$kode = 1;
}
$kode_max = str_pad($kode, 4, "0", STR_PAD_LEFT);
$kode_jadi = $kode_max;
return $kode_jadi;
}
public function import_data($datareceiving)
{
$jumlah = count($datareceiving);
if ($jumlah > 0) {
// Replcae (namatable , Parameter variable upload)
$this->db->replace('receiving', $datareceiving);
}
}
public function today()
{
$today = date('ymd');
return $today;
}
public function tgl()
{
$tgl = date('d');
return $tgl;
}
public function bln()
{
$tgl = date('m');
return $tgl;
}
public function joinMasterpart()
{
$this->db->select('*');
$this->db->from('receiving');
$this->db->join('master_part', 'receiving.number_part = master_part.part_number','INNER');
$this->db->join('master_customer', 'master_part.id_customer = master_customer.id_customer','INNER');
$query = $this->db->get();
return $query->result();
}
public function joinMasterpartBarcode()
{
$this->db->select('*');
$this->db->from('receiving');
$this->db->join('master_part', 'receiving.number_part = master_part.part_number','INNER');
$this->db->join('master_customer', 'master_part.id_customer = master_customer.id_customer','INNER');
$query = $this->db->get();
return $query->result();
}
public function detail($part_number)
{
$this->db->select('*');
$this->db->from('receiving');
$this->db->join('master_part', 'receiving.number_part = master_part.part_number');
$this->db->where('part_number',$part_number);
$this->db->join('master_customer', 'master_part.id_customer = master_customer.id_customer');
$query = $this->db->get();
return $query->row();
}
and this my Html
<div id="wrapper">
<!-- load sidebar -->
<?php $this->load->view('partials/sidebar.php') ?>
<div id="content-wrapper" class="d-flex flex-column">
<div id="content" data-url="<?= base_url('incoming') ?>">
<!-- load Topbar -->
<?php $this->load->view('partials/topbar.php') ?>
<div class="container-fluid">
<div class="clearfix">
<div class="float-left">
<h1 class="h3 m-0 text-gray-800"><?= $title ?></h1>
</div>
<div class="float-right">
<i class="fa fa-file-excel"></i> Export Excel
<i class="fa fa-file-pdf"></i> Export Pdf
<i class="fa fa-plus"></i> Tambah
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#importdataketua">
<i class="fa fa-file-import"></i> Import
</button>
</div>
</div>
<hr>
<?php if ($this->session->flashdata('success')) : ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?= $this->session->flashdata('success') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php elseif ($this->session->flashdata('error')) : ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?= $this->session->flashdata('error') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php endif ?>
<div class="card shadow">
<div class="card-header"><strong>Receiving</strong></div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<td>Lot Number</td>
<td>Upload Id</td>
<td>Part Number</td>
<td>Description</td>
<td>Shift</td>
<td>Date Production</td>
<td>Date Receive</td>
<td>Qty Transfer</td>
<td>Pic</td>
<td>Txndate</td>
<td>Id Customer</td>
<td>Customer Name</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<?php $no = 1; ?>
<?php foreach ($all_receiving as $rows_allReceiving) { ?>
<tr>
<td>
<?= $rows_allReceiving->id_customer ?><?= $rows_allReceiving->lot_number ?>
<i class="fa fa-barcode"></i> Generate
</td>
<td><?= $rows_allReceiving->upload_id?></td>
<td>
<?= $rows_allReceiving->number_part?>
</td>
<td><?= $rows_allReceiving->description?></td>
<td><?= $rows_allReceiving->shift?></td>
<td><?= $rows_allReceiving->date_production ?></td>
<td><?= $rows_allReceiving->date_receive ?></td>
<td><?= $rows_allReceiving->qty_transfer ?></td>
<td><?= $rows_allReceiving->pic ?></td>
<td><?= $rows_allReceiving->txndate ?></td>
<td><?= $rows_allReceiving->id_customer ?></td>
<td><?= $rows_allReceiving->nama_customer ?></td>
<td>
<i class="far fa-folder"></i> Detail
<a onclick="return confirm('apakah anda yakin?')" href="<?= base_url('receiving/hapus/' . $rows_allReceiving->receive_id) ?>" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> Hapus</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- load footer -->
<?php $this->load->view('partials/footer.php') ?>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="importdataketua" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Import Excel</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<?= form_open_multipart('receiving/uploadexcel') ?>
<div class="form-group">
<label for="exampleFormControlFile1">Upload File</label>
<input type="file" class="form-control-file" id="exampleFormControlFile1" name="importexcel">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary"><i class="fa fa-file-import"></i> Upload</button>
</div>
<?= form_close(); ?>
</div>
</div>
</div>
<?php $this->load->view('partials/js.php') ?>
<script src="<?= base_url('sb-admin/js/demo/datatables-demo.js') ?>"></script>
<script src="<?= base_url('sb-admin') ?>/vendor/datatables/jquery.dataTables.min.js"></script>
<script src="<?= base_url('sb-admin') ?>/vendor/datatables/dataTables.bootstrap4.min.js"></script>
<script>
function autofill() {
$.ajax({
url: 'receiving/autofillAjax',
data: 'part_number' + part_number,
}).success(function(data) {
alert('masuk');
});
}
</script>
HELP
am stuck here. I have a project that makes a table receiving with the added method using an import file with Xlsx extension ( Excel ) , they have 21 column inside table mysql and user just import file in a part. and I want it when the upload is successful. All empty data in the table is quickly filled by retrieving data from another table such as vlookup. am using Codeigniter 3.
I am trying to display messages in the error section from sender and receiver, both returning view mes_res from MessageController, but it is displaying an error message.
#controller method:
public function respone_msg($myid){
$dd = DB::table('messeges')->where(['is_read'=>0,'sender_id' =>$myid , 'receiver_id' => Session::get('id')])->get();
$myCount = count($dd);
var_dump($myCount);
$sendmsesgesreal = DB::table('messeges')->where(['sender_id' => Session::get('id') , 'receiver_id' => $myid])->orWhere(['receiver_id' => Session::get('id') ])->get();
//return view('users.mes_res')->with(['msg_data' => $sendmsesgesreal, 'user_id' => $myid, 'conv_id' => $sendmsesgesreal[0]->conversation_id]);
return view('users.mes_res')->with(['msg_data' => $sendmsesgesreal, 'user_id' => $myid, 'conv_id' => $sendmsesgesreal[0]->conversation_id])->header('Cache-Control', 'no-cache, no-store, must-revalidate');
}
view mes_reg:
<div class="messages-headline">
<i class="icon-feather-trash-2"></i> Delete Conversation
</div>
<!-- Message Content Inner -->
<div class="message-content-inner">
<?php
foreach ($msg_data as $msg) {
//
if($msg->sender_id==Session::get('id') && $msg->receiver_id==$user_id) //conv_id
{
$getuserdat1 = DB::table('profile_users')->where('user_id',$msg->sender_id)->get();
// print_r($msg);
if (count($getuserdat1)>0)
{
$fullname=$getuserdat1[0]->fname.' '.$getuserdat1[0]->lname;
if ($getuserdat1[0]->profile_images)
{
$img11 = url('')."/public/uploads/".$getuserdat1[0]->profile_images;
}
else
{
$img11 = url('')."/public/users/images/user-avatar-placeholder.png";
}
}
else
{
$img11 = url('')."/public/users/images/user-avatar-placeholder.png";
}
echo '<input type="hidden" name="receiver_id" id="receiver_id" value="'.$msg->sender_id.'">';
//print_r($img11);
?>
<div class="message-time-sign">
<span>{{ \Carbon\Carbon::parse($msg->CreatedBydate)->diffForhumans() }}</span>
</div>
<div class="message-bubble me">
<div class="message-bubble-inner">
<div class="message-avatar"><img src="{{$img11}}" alt="" /></div>
<div class="message-text"><p>{{$msg->messeges}}</p></div>
</div>
<div class="clearfix"></div>
</div>
<?php }
elseif($msg->sender_id==$user_id)
//else
{
//print_r($msg);
// $receiverdata = DB::table('messeges')
// ->where('sender_id',$msg->sender_id)->get();
// print_r($receiverdata);
//print_r($msg);
$getuserdat11 = DB::table('profile_users')->where('user_id',$msg->sender_id)->get();
if(count($getuserdat11)>0)
{
if ($getuserdat11[0]->profile_images)
{
$img111 = url('')."/public/uploads/".$getuserdat11[0]->profile_images;
}
else
{
$img111 = url('')."/public/users/images/user-avatar-placeholder.png";
}
}
else
{
$img111 = url('')."/public/users/images/user-avatar-placeholder.png";
}
echo '<input type="hidden" name="receiver_id" id="receiver_id" value="'.$msg->sender_id.'">';
//print_r($img111);
?>
<div class="message-time-sign">
<span>{{ \Carbon\Carbon::parse($msg->CreatedBydate)->diffForhumans() }}</span>
</div>
<div class="message-bubble">
<div class="message-bubble-inner">
<div class="message-avatar"><img src="{{$img111}}" alt="" /></div>
<div class="message-text"><p>{{$msg->messeges}}</p></div>
</div>
<div class="clearfix"></div>
</div>
<?php }
?>
</div>
I'm using the checkbox to sending an email that already selected. after the email sent, the status sendinvoice change to Y. everything is fine when I select 1 checkbox. but when I choose multiple checkboxes, the function only update 1 checkbox
How to make it can run update function with multiple checkboxes?
the view code for checkbox and button below
<button type="button" class="btn waves-effect waves-light btn-info" id="btn-sentcitilink"> Sent Email</button>
<?php
foreach($result as $row){
?>
<form method="post" action="<?php echo base_url(); ?>cms/emailcitilink" id="sentemailcitilink">
<?php
}
?>
<table id="myTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Send Invoice </th>
<th>Booking ID</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $row){
?>
<tr>
<td>
<?php if($row['sendinvoice'] == 'N'){ ?>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="books[]" id="tableDefaultCheck/<?php echo $row['booking_id']?>" value="<?php echo $row['booking_id']?>">
<label class="custom-control-label" for="tableDefaultCheck/<?php echo $row['booking_id'] ?>"></label>
</div>
<?php } ?>
<?php if($row['sendinvoice'] == 'Y'){ ?>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="tableDefaultCheck3" checked disabled>
<label class="custom-control-label" for="tableDefaultCheck3"></label>
</div>
<?php } ?>
</td>
<td>
<div class="hover-link">
<a href="<?php echo base_url(); ?>cms/transaction/view/<?php echo $row['_id'] ?>">
<?php echo $row['booking_id'] ?>
</a>
</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<script>
$(document).ready(function() {
$("#check-all").click(function() {
if ($(this).is(":checked"))
$(".check-item").prop("checked", true);
else // Jika checkbox all tidak diceklis
$(".check-item").prop("checked", false);
});
$("#btn-sentcitilink").click(function() {
var confirm = window.confirm("Apakah Anda mengirim email data-data ini?");
if (confirm)
$("#sentemailcitilink").submit();
});
});
</script>
The controller code
function emailtocitilink(){
$books = $_POST['books'];
$get_trans = $this->cms_model->get_transaction_by_list_trip($tripsData);
foreach($get_trans as $row){
$arr_data = array(
'booking_id' => $row['TRANSIDMERCHANT'],
);
array_push($arr, $arr_data);
}
$data = $this->data;
$data['result'] = $arr;
$datas = array(
'SendINVOICE' => "Y"
);
$insert = $this->cms_model->update_transaction($datas, $books);
redirect(base_url().'cms/citilinktransaction/');
}
Model
function get_transaction_by_list_trip($TripUUID){
return $this->mongo_db
->where_in('TripUUID', $TripUUID)
->where(array('PAYMENTCHANNEL' => 'TESTINGCHANNEL'))
->order_by(array('transaction_date' => 'desc'))
->get('tr_transaction');
}
function update_transaction($datas, $books){
return $this->mongo_db->where_in('TRANSIDMERCHANT', $books)
->set($datas)
->update('tr_transaction',['multi' => TRUE]);
}
On model, it should be 'multiple' => true
Use update_all to update multiple records:
$this->mongo_db
->set($datas, ["multi" => true])
->where_in('TRANSIDMERCHANT', $books)
->update_all('tr_transaction');
Hi im working on my workshop tools project.
Now i have some strange action sometimes when i pressed the add to cart button (mine was named pinjam) it just going back to the login page because the session destroyed. Anyone has this strange thing happened? or Can you help me?
The scenario is like this..
I pressed the add to cart button on one of much tools that can i borrow, then it post to the add_to_cart function on my controller and reload the #cart_content div on that page with new added data with jquery / ajax
Controller Siswa
function index(){
$data['guru'] = $this->model_akun->getnamaguru();
$data['data']=$this->model_alat->getAll();
$this->load->view('siswa/dashboard',$data);
}
function add_to_cart(){
if($this->model_alat->validate_add_cart_item() == TRUE){
// Check if user has javascript enabled
if($this->input->post('ajax') != '1'){
redirect('siswa'); // If javascript is not enabled, reload the page with new data
}else{
echo 'true'; // If javascript is enabled, return true, so the cart gets updated
}
}
}function show_cart(){
$this->load->view('siswa/cart');
}
Model_Alat
function validate_add_cart_item(){
$id = $this->input->post('id_alat'); // Assign posted id_alat to $id
$cty = $this->input->post('quantity'); // Assign posted quantity to $cty
//$this->db->where('id_alat', $id); // Select where id matches the posted id
$query = $this->db->query('select * from alat where id_alat="'.$id.'"')->result(); // Select the products where a match is found and limit the query by 1
//$ss = $this->input->post('ajax');
//echo $query['id_alat'];
//echo "<script>alert(".$cty.");
// </script>";
// Check if a row has been found
if($query > 0){
foreach ($query as $row){
$data = array(
'id' => $id,
'qty' => $cty,
'price' => '0',
'name' => $row->nama_alat
);
$this->cart->insert($data);
return TRUE;
}
// Nothing found! Return FALSE!
}else{
echo "<script>alert('FALSE no rows :(');</script>";
return FALSE;
}
}
JQUERY
<script>
$(document).ready(function() {
/*place jQuery actions here*/
var link = "/weteies/index.php/"; // Url to your application (including index.php/)
$("div.subalat form").submit(function() {
// Get the product ID and the quantity
var id = $(this).find('input[name=id_alat]').val();
var qty = $(this).find('input[name=quantity]').val();
$.post(link + "siswa/add_to_cart", { id_alat: id, quantity: qty, ajax: '1' },
function(data){
// Interact with returned data
if(data == 'true'){
$.get(link + "siswa/show_cart", function(cart){ // Get the contents of the url cart/show_cart
$("#cart_content").html(cart); // Replace the information in the div #cart_content with the retrieved data
});
}else{
alert("Product does not exist");
}
});
});
});
siswa/cart (for viewing the cart list)
##siswa/cart view
<div class="table-responsive">
<?php echo form_open('siswa/update_cart'); ?>
<table class="table table-bordered">
<thead >
<tr>
<th>Alat</th>
<th>Jumlah</th>
<!--<th>Total</th>-->
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php $a=0; $b=0;foreach($this->cart->contents() as $items): ?>
<tr>
<!--<input type="hidden" id="id_peminjam" name="id_peminjam" value="'.$this->session->userdata('ses_id').'"/>-->
<td><?php echo form_hidden('rowid['.$a.']', $items['rowid']);
echo $items['name']; ?></td>
<td><?php echo form_input(array('name' => 'qty['.$a.']', 'value' => $items['qty'], 'maxlength' => '2'), '', 'class="form-control form-control-sm"'); ?></td>
<!--<td><button type="button" id="'.$items['rowid'].'" class="romove_cart btn btn-danger btn-sm">Cancel</button></td>-->
<td><?php echo form_submit('', 'Update', 'class="btn btn-accept btn-sm"');
$b=$a+1;?>
</tr>
<?php $a++; endforeach; ?>
</tbody>
</table>
<?php echo form_hidden('jumlah_alat', $b);
echo form_close();?>
<?php echo form_open('siswa/sub_cart'); ?>
<table class="table">
<tr>
<td >
<select name="id_guru" class="form-control form-control-sm">
<option>Pilih Guru</option>
<?php foreach($guru as $gurus): echo '<option value='.$gurus->id_akun.'>'. $gurus->nama .'</option>'; endforeach;?>
</select>
</td>
<td>
<?php $hitung=0; $b=0; foreach($this->cart->contents() as $items): ?>
<?php echo form_hidden('id_alat'.$hitung.'', $items['id']);
echo form_hidden('jumlah_pinjam'.$hitung.'', $items['qty']);
echo form_hidden('id_siswa', $this->session->userdata('ses_id'));
$b=$hitung+1;
$hitung++;
endforeach;
echo form_hidden('jumlah_alat', $b);
echo anchor('siswa/empty_cart', 'Hapus Semua', 'class="btn btn-danger btn-sm col-sm-5"'); ?>
<?php echo form_submit('', 'Pinjam!', 'class="btn btn-primary btn-sm col-sm-5"');?>
</td>
</tr>
</table>
<?php echo form_close(); ?>
</div>
FORM siswa/dashboard
<!DOCTYPE html>
<head>
<?php $this->load->view("admin/_partials/head.php") ?>
</head>
<body id="page-top">
<!-- Navbar-->
<?php $this->load->view("siswa/_partials/navbar.php") ?>
<div id="wrapper">
<!-- Sidebar-->
<?php $this->load->view("siswa/_partials/sidebar.php") ?>
<div id="content-wrapper">
<div class="container-fluid">
<div class="row ">
<div class="col-md-6">
<div class="card mb-3">
<h4 class="card-header">Alat Tersedia</h4>
<br>
<div class="row card-body">
<?php foreach ($data as $row) : ?>
<div class="col-md-6">
<div class="card mb-3">
<div class="card-header text-center"><?php echo $row->nama_alat;?>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-7">
Tersedia
</div>
<div class="col-md-5">
<input value="<?php echo $row->jumlah;?>" class="form-control form-control-sm" readonly>
</div>
</div>
<div class="subalat">
<?php echo form_open(''); ?>
<div class="row">
<div class="col-md-7">
Mau Brp?
</div>
<div class="col-md-5">
<?php echo form_hidden('id_alat', $row->id_alat);
echo form_input('quantity', '1', 'maxlength="2" class="form-control form-control-sm"'); ?>
</div>
</div>
<br>
<?php echo form_submit('add', 'Pinjam','class="btn btn-success btn-block col-md"'); ?>
<?php echo form_close(); ?>
</div>
</div>
</div>
</div>
<?php endforeach;?>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card mb-3">
<h4 class="card-header">List Pinjam</h4>
<!--<div class="card-body">-->
<div id="cart_content">
<?php $this->load->view('siswa/cart'); ?>
</div>
<!--</div>-->
<div class="card-footer small text-muted">
Jika jumlah alat nya 0(nol), alat akan dihapus. Page rendered in <strong>{elapsed_time}</strong> seconds.
</div>
</div>
</div>
</div><!-- /.row -->
</div><!-- /.content-fluid -->
<!-- Sticky Footer -->
<?php $this->load->view("siswa/_partials/footer.php") ?>
</div>
<!-- /.content-wrapper -->
</div>
<!-- /#wrapper -->
<?php $this->load->view("siswa/_partials/scrolltop.php") ?>
<!-- Modal-->
<?php $this->load->view("siswa/_partials/modal.php") ?>
<!-- Js-->
<?php $this->load->view("siswa/_partials/js.php") ?>
</body>
<script>
$(document).ready(function() {
/*place jQuery actions here*/
var link = "/weteies/index.php/"; // Url to your application (including index.php/)
$("div.subalat form").submit(function() {
// Get the product ID and the quantity
var id = $(this).find('input[name=id_alat]').val();
var qty = $(this).find('input[name=quantity]').val();
$.post(link + "siswa/add_to_cart", { id_alat: id, quantity: qty, ajax: '1' },
function(data){
// Interact with returned data
if(data == 'true'){
$.get(link + "siswa/show_cart", function(cart){ // Get the contents of the url cart/show_cart
$("#cart_content").html(cart); // Replace the information in the div #cart_content with the retrieved data
});
}else{
alert("Product does not exist");
}
});
});
});
</script>
</html>
Login controller
class Login extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model("model_login");
}
function index(){
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|trim');
if($this->form_validation->run()==FALSE){
$session = $this->session->userdata('isLoggedin');
if($session == FALSE){
$this->load->view('login');
}
else{
redirect('');
}
}
else{
$email=$this->input->post('email');
$password=$this->input->post('password');
$cek_akun=$this->model_login->auth_akun($email,$password);
if($cek_akun->num_rows() > 0){
$user_data=$cek_akun->row_array();
$this->session->set_userdata('isLoggedin',TRUE);
$this->session->set_userdata('ses_id',$user_data['id_akun']);
$this->session->set_userdata('ses_nama',$user_data['nama']);
if($user_data['level']=='admin'){ //level admin
$this->session->set_userdata('level','admin');
redirect('admin');
}
else if($user_data['level']=='aspiran'){ //level aspiran
$this->session->set_userdata('level','aspiran');
redirect('aspiran');
}
else if($user_data['level']=='guru'){ //level guru
$this->session->set_userdata('level','guru');
redirect('guru');
}
else if($user_data['level']=='siswa'){ //level siswa
$this->session->set_userdata('level','siswa');
redirect('siswa');
}
}
else{
$this->load->view('login');
echo "<script>alert('Failed Login: Check your username and password!');
</script>";
}
}
}
function logout(){
$this->session->sess_destroy();
$url=base_url('');
redirect($url);}}
there is data entered in foreach loop but not insert into database there is half data insert into database but there is no work foreach loop.....after insert half data , theres not update remaining half data.....why this happen
the code is
<?php
include_once('config.php');
if(isset($_POST["email_verify_btn"])) {
$email = $_POST["email_verify"];
$i = 1;
if(strpos($email,"\n")) {
$text = explode("\n",$email);
foreach ($text as $abc) {
$i++;
$status = 1;
$c_by = 1;
$c_date = date('Y-m-d H:i:s');
$c_ip = $_SERVER['REMOTE_ADDR'];
$_SESSION['date_time'] = $c_date;
$insert = $connect->query("INSERT INTO `email_verify_list`(`primary_email`,`session`,`status`,`created_by`, `created_date`, `created_ip`) VALUES ('$abc','".$_SESSION['date_time']."','$status','$c_by','$c_date','$c_ip')");
if($insert) {
$select_status = $connect->query("SELECT * from `email_verify_list` where session='".$_SESSION['date_time']."'");
$fetch_selected_status = $select_status->fetch_assoc();
$fetch_email= $fetch_selected_status['primary_email'];
if(filter_var($fetch_email, FILTER_VALIDATE_EMAIL)) {
function domain_exists($fetch_email)
{
$domain = substr(strrchr($fetch_email, "#"), 1);
$arr = #dns_get_record($domain, DNS_MX);
if ($arr[0]['host'] == $domain && !empty($arr[0]['target'])) {
return $arr[0]['target'];
}
}
if(domain_exists($fetch_email)){
$domain = substr(strrchr($fetch_email, "#"), 1);
$data = #dns_get_record($domain, DNS_MX);
if($data) {
$status = "email id is valid";
}
if (is_array($data) || is_object($data)) {
foreach ($data as $key1) {
$host = $key1['host'];
$target = $key1['target'];
$target_ip = gethostbyname($key1['target']);
}
}
} else {
$status = "mx recored not exist";
}
} else {
$status = "not in syntax" ;
}
$insert_all_data = $connect->query("UPDATE `email_verify_list` SET `host_name`='$host',`target`='$target',`target_ip`='$target_ip',`status`='$status' WHERE session='".$_SESSION['date_time']."'");
if($insert_all_data) {
echo "<script>alert('successfully');</script>";
} else {
echo "<script>alert('!!!!!not successfully');</script>";
}
}
}
}
}
?>
<form method="post" action="" >
<div class="tab-content">
<div class="tab-pane padding-20 active slide-left" id="tab1">
<div class="row row-same-height">
<div class="col-md-12">
<div class="padding-30">
<div class="row clearfix">
<div class="col-sm-3">
<div class="form-group form-group-default">
<label><font size="2">ENTER YOUR EMAIL <span class="glyphicon glyphicon-envelope"></span></font></label><br>
<textarea cols="43" rows="9" name="email_verify" style="border-color:white;border-width:thin;padding:4pt;" multiple/></textarea><br>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-3">
<button type="submit" name="email_verify_btn" class="btn btn-lg btn-info" style="padding:11pt;width:200px;"/><span><b><font size="2">SUBMIT</font></b></span></button>
</div>
</div> <br><br>
<div class="row clearfix">
<div class="col-sm-12">
<table width="100%" class="table ">
<tr class="success">
<th>PRIMARY EMAIL <span class="glyphicon glyphicon-envelope"></span></th>
<th>HOST NAME</th>
<th>TARGET</th>
<th>TARGET IP</th>
<th>STATUS</th>
</tr>
<?php
$select = $connect->query("SELECT * from `email_verify_list` where session='".$_SESSION['date_time']."' order by id");
while($row = $select->fetch_assoc()) {
?>
<tr>
<td><?php echo $row['primary_email']; ?></td>
<td><?php echo $row['host_name']; ?></td>
<td><?php echo $row['target']; ?></td>
<td><?php echo $row['target_ip']; ?></td>
<td><?php echo $row['status']; ?></td>
</tr>
<?php } ?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>