I am unable to update cart on checkout page. I do not know what is Happen.
Here is my code.
function update_cart()
{
$rowid =$this->input->post('rowid');
$price =$this->input->post('price');
$qty = $this->input->post('qty');
$pr = preg_replace( '/,/', '', $price);
$amount = $pr * $qty;
$data = array(
'rowid' => $rowid,
'price' => $price,
'amount' => $amount,
'qty' => $qty
);
$this->cart->update($data);
redirect('checkout');
}
Here is my car view code .I am trying to update cart value here.No error showing. I unable to solve .Any help .Only update cart is not working . Other functionality is working good .add to cart delete to cart but update to cart does not working . I create session table and also try other suggestion and solution form stack overflow.
<form action="<?=base_url()?>cart/update_cart" method="post">
<div class="panel panel-info">
<div class="panel-heading">
<div class="panel-title">
<div class="row">
<div class="col-xs-6">
<h5><span class="glyphicon glyphicon-shopping-cart"></span> Shopping Cart</h5>
</div>
<div class="col-xs-6">
<a href="<?=base_url()?>">
<button type="button" class="btn btn-primary btn-sm btn-block">
<span class="glyphicon glyphicon-share-alt"></span> Continue shopping
</button>
</a>
</div>
</div>
</div>
</div>
<div class="panel-body">
<?php $i = 1; ?>
<?php
//print_r($this->cart->contents() );
//die;
foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<div class="row">
<div class="col-xs-2">
<img class="img-responsive" src="<?=base_url()?>uploads/product/<?=$items['image'];?>" />
</div>
<div class="col-xs-4">
<h5 class="product-name">
<strong><?php echo $items['name']; ?>
</strong>
<?=$items['options'];?>
</h5>
</div>
<div class="col-xs-6">
<div class="col-xs-6 text-right">
<h6><strong><?= $this->cart->format_number($items['price']); ?>
<span class="text-muted">x</span></strong></h6>
</div>
<div class="col-xs-4">
<?php //echo form_input(array('name' => $i.'[qty]', 'value' => $items['qty'], 'size' => '1')); ?>
<input type="text" name="qty" min="1" value="<?=$items['qty'] ?>" maxlength="1" style="width: 50%;">
<input type="hidden" name="price" value="<?=$items['price'] ?>">
<input type="hidden" name="name" value="<?=$items['name'] ?>">
<input type="hidden" name="description" value="<?=$items['description'] ?>">
</div>
<div class="col-xs-2">
<a href="<?=base_url()?>cart/remove/<?=$items['rowid']?>">
<button type="button" class="btn btn-link btn-xs">
<span class="glyphicon glyphicon-trash" onclick="confirm('Are you sure want to delete')";> </span>
</button>
</a>
</div>
</div>
</div>
<hr>
<?php $i++; ?>
<?php endforeach; ?>
at view .... use only two input
<input type="text" name="qty[]" min="1" value="<?=$items['qty'] ?>" maxlength="1" style="width: 50%;">
<input type="hidden" name="rowid[]" value="<?=$items['rowid'] ?>">
at controller
you only need to change qty if you are going to update a cart
function update_cart()
{
for ($i=0; $i < count($_POST) - 1; $i++) {
$data = array(
'rowid' => $_POST['rowid'][$i],
'qty' => $_POST['qty'][$i]
);
$this->cart->update($data);
}
redirect('checkout');
}
Related
CONTROLLER
In my controller I add product like this, cart is redirecting but not adding a product, how can this be fixed?
function tambah()
{
$data_produk= array('id' => $this->input->post('id'),
'nama_produk' => $this->input->post('nama_produk'),
'harga' => $this->input->post('harga'),
'gambar' => $this->input->post('gambar'),
//'seller' => $this->input->post('seller'),
'qty' => $this->input->post('qty')
);
//die(print_r($data_produk));
$this->cart->insert($data_produk);
$cart = $this->cart->contents();
if(!empty($cart)){
// print_r($cart);
}
redirect('product');
}
VIEW ;
<div class="col-md-8">
<div class="product_list">
<div class="row">
<?php foreach($shopall as $row){ ?>
<div class="col-lg-6 col-sm-6">
<div class="single_product_item">
<img src="assets/img/categori/product1.png" alt="" class="img-fluid">
<div class="card_area">
<form action="<?php echo base_url();?>cart/tambah" method="post" accept-charset="utf-8">
<div class="product_count_area" style="margin:-40PX -35PX 0PX 0PX;">
<p style="text-align:center;">Rp. <?php echo number_format($row['harga'],0,",",".");?></p>
<div class="product_count d-inline-block">
<span class="product_count_item inumber-decrement"> <i class="ti-minus"></i></span>
<input class="product_count_item input-number" name="qty" type="number" value="1" min="1" max="99">
<span class="product_count_item number-increment"> <i class="ti-plus"></i></span>
</div>
</div>
<p><?php echo $row['nama_produk'] ?></p>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" />
<input type="hidden" name="nama_produk" value="<?php echo $row['nama_produk']; ?>" />
<input type="hidden" name="harga" value="<?php echo $row['harga']; ?>" />
<input type="hidden" name="gambar" value="<?php echo $row['gambar']; ?>" />
<div style="text-align:center; margin:-20px;" class="add_to_cart">
<!--<button type="submit" class="btn_3">add to cart</button>-->
<button type="submit" class="btn btn-sm btn-success"><i class="glyphicon glyphicon-shopping-cart"></i> Beli</button>
</div>
</form>
</div>
</div>
</div>
<?php } ?>
</div>
<div class="load_more_btn text-center">
Load More
</div>
</div>
</div>
In my last project I could use cart functionality with it, but in this project cart remains empty, can you point me where my code is wrong?
Codeigniter Cart Using English in it array keys, (unless you modified it somehow)
This should work - Notes: Add any extra data you may need to save under options, don't define your own array key. check here for more Codeingiter Cart
$data_produk = array(
'id' => 'sku_123ABC',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'L', 'Color' => 'Red')
);
instead of this
$data_produk= array('id' => $this->input->post('id'),
'nama_produk' => $this->input->post('nama_produk'),
'harga' => $this->input->post('harga'),
'gambar' => $this->input->post('gambar'),
//'seller' => $this->input->post('seller'),
'qty' => $this->input->post('qty')
);
Try to map that according to your language
This is part of the code, it made me cannot login, i don't know where is the problem. When i tried to log in, it has no effect. Sorry for my bad english.
public function login()
{
if ($this->identity->is_admin())
redirect('admin/dashboard');
if ($this->identity->is_contestant())
redirect('contestant/dashboard');
$this->form_validation->set_rules('form[username]', $this->lang->line('username'), 'trim|required|max_length[50]');
$this->form_validation->set_rules('form[password]', $this->lang->line('password'), 'trim|required|max_length[50]');
if ($this->form_validation->run())
{
$credentials = $this->input->post('form');
if ($this->identity->login($credentials))
{
if ($this->identity->is_admin())
redirect('admin/dashboard');
else
redirect('contestant/dashboard');
}
else
{
$this->session->set_flashdata('error', $this->lang->line('wrong_credentials'));
redirect('site/login');
}
}
else
{
$this->ui['header']['title'] = $this->lang->line('login');
$this->ui['header']['page'] = 'login';
$this->load->view('site/header', $this->ui['header']);
$this->load->view('site/login', $this->ui['content']);
$this->load->view('footer', $this->ui['footer']);
}
}
Here are the login site source code.
<div class="container">
<div class="row">
<div class="col-md-12">
<ul class="breadcrumb">
<li>
<i class="glyphicon glyphicon-off"></i> <?php echo $this->lang->line('please_login'); ?>
</li>
</ul>
</div>
</div>
<?php if ($this->session->flashdata('error')) : ?>
<div class="row">
<div class="col-md-5">
<div class="alert alert-danger">
<?php echo $this->session->flashdata('error'); ?>
</div>
</div>
</div>
<?php endif; ?>
<div class="row">
<div class="col-md-12">
<form class="form-horizontal" action="" method="post">
<div class="form-group<?php echo form_error('form[username]') ? ' has-error' : ''; ?>">
<label class="col-sm-1 control-label"><?php echo $this->lang->line('username'); ?>:</label>
<div class="col-sm-4">
<input name="form[username]" type="text" maxlength="30" class="form-control" value="<?php echo set_value('form[username]'); ?>" autofocus="on"/>
<span class="help-block"><?php echo form_error('form[username]'); ?></span>
</div>
</div>
<div class="form-group<?php echo form_error('form[password]') ? ' has-error' : ''; ?>">
<label class="col-sm-1 control-label"><?php echo $this->lang->line('password'); ?>:</label>
<div class="col-sm-4">
<input name="form[password]" type="password" maxlength="30" class="form-control"/>
<span class="help-block"><?php echo form_error('form[password]'); ?></span>
</div>
</div>
<div class="form-actions col-sm-offset-1">
<button type="submit" class="btn btn-danger col-sm-3"><i class="glyphicon glyphicon-user"></i> <?php echo $this->lang->line('login'); ?></button>
</div>
</form>
</div>
</div>
is it true that php7.1 is not supported by CI 3.0.0 so the error happened by this?
I was uploaded Image in database Successfully. But not succeed to fetch image from database.
i want to fetch the image from database.
here is my code,
controller -> login.php
public function user_update(){
$this->load->model('login_model');
$this->form_validation->set_rules('fname', 'First Name','required');
$this->form_validation->set_rules('lname', 'Last Name','required');
$this->form_validation->set_rules('cnumber', 'Contact Number','required|min_length[10]|max_length[10]|numeric');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'doc|docx|pdf|gif|jpg|png|xlsx';
$config['max_size'] = 10000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if (( ! $this->upload->do_upload('image')) && ($this->form_validation->run() === FALSE ))
{
$this->load->view('student/home');
}
else
{
$data = array('upload_data' => $this->upload->data());
$image_name=($data['upload_data']['file_name']);
$resume=base_url().$image_name;
$udata = array(
'id' => $this->input->post('id'),
'fname' => $this->input->post('fname'),
'mname' => $this->input->post('mname'),
'lname' => $this->input->post('lname'),
'email' => $this->input->post('email'),
'address' => $this->input->post('address'),
'cnumber' => $this->input->post('cnumber'),
'image'=> $resume
);
$this->login_model->Updateuser($udata);
}
}
model file:- login_model.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class login_model extends CI_Model
{
function Updateuser($param) {
$id = $param['id'];
$usar1 = array(
'Student_Name' => $param['fname'],
'm_name' => $param['mname'],
'l_name' => $param['lname'],
'Student_Email' => $param['email'],
'contact_no' => $param['cnumber'],
'Address' => $param['address'],
'image' => $param['image']
);
$this->db->where('Student_id', $id);
$this->db->update('students', $usar1);
//echo ($this->db->last_query());
//exit();
$sturesult = $this->login_model->get_student_list();
$data['Stulist'] = $sturesult;
$this->load->view('student/default_list',$data);
}
}
view file:- edit_info.php
<div class="container" id='main-layout' style="border-top: 1px solid #D14B54; background: #f5f5f5f5">
<div class="row">
<div class="col-md-8 col-sm-8">
<div class="ajaxResponse"><input type="hidden" name="ajaxResponse"></div>
<div class="row" style="padding: 10px 5px;">
<?php $id = $this->uri->segment(3); if(!empty($id)): ?>
<div class="">
<?php echo validation_errors();
echo $lname;
?>
<div class="thumbnail familycol" style="padding:16px">
<?php echo form_open_multipart('login/user_update'); ?>
<legend>Personal Information</legend>
<div class="row">
<?php //echo form_label('Id :'); ?> <?php echo form_error('id'); ?>
<input type="hidden" name="id" value="<?php echo $row->Student_id; ?>" class="form-control input-sm" placeholder="id"/>
<!-- <label class="required">First name</label>-->
<div class="col-xs-6 col-md-6">
<label for="First Name">First Name:</label>
<input type="input" name="fname" class="form-control" value="<?php echo $row->Student_Name;?>"/><font color="red"><?php echo form_error('fname'); ?></font>
</div>
<div class="col-xs-6 col-md-6">
<!--<label class="required">Middle name</label>-->
<label for="Last Name">Middle Name:</label>
<input type="input" name="mname" class="form-control" value="<?php echo $row->m_name?>"/><font color="red"><?php echo form_error('mname'); ?></font>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-md-6">
<!--<label class="required">Last name</label>-->
<label for="Last Name">Last Name:</label>
<input type="input" name="lname" class="form-control" value="<?php echo $row->l_name ;?>"/><font color="red"><?php echo form_error('lname'); ?></font>
</div>
<div class="col-xs-6 col-md-6">
<?php echo form_label('Email :'); ?> <?php echo form_error('email'); ?>
<input type="text" name="email" value="<?php echo $row->Student_Email; ?>" class="form-control input-sm" placeholder="Email" />
</div>
</div>
<br>
<div class="row">
<div class="col-sm-6">
<!--<label>Address</label>-->
<label for="text">Address</label>
<textarea name="address" class="form-control"><?php echo $row->Address ;?></textarea><font color="red"><?php echo form_error('address'); ?></font>
</div>
<div class="col-sm-6">
<label for="text">Contact Number</label>
<textarea name="cnumber" class="form-control"><?php echo $row->contact_no ;?></textarea><font color="red"><?php echo form_error('cnumber'); ?></font>
</div>
<br/>
</div>
<br/>
<label for='uploaded_file'>Select A File To Upload:</label>
<input type="file" name="image" accept="image/*" value="upload">
<br/>
<button class="btn btn-lg btn-primary btn-block signup-btn" type="submit" style="margin-top: 5px;">
Update my Profile</button>
</div>
</div>
<?php endif;?>
</div>
</div>
</div>
</div>
Ok Lets Put Code in your View file:
<img src="<?php echo base_url('uploads/').$Stulist[$i]->image; ?>"
You have updated the wrong image directory of uploaded images in database.
Simply update the following lines of code
$data = array('upload_data' => $this->upload->data());
$image_name=($data['upload_data']['file_name']);
$resume=base_url().$image_name;
to
$data = array('upload_data' => $this->upload->data());
$image_name=($data['upload_data']['file_name']);
$resume=base_url('uploads').$image_name;
here the base_url points to the uploads directory where you have uploaded your images.
Agent controller:
public function index() {
if (!empty($_SESSION['admin'])) {
$data = array(
'page_title' => 'Agent',
'page_name' => 'agent/index',
'result' => $this->agent_model->list_all()
);
$this->load->view('template', $data);
} else {
redirect('login');
}
}
Agent model:
public function list_all() {
$data = 'agent.id,agent.name,agent.mobile,agent.vehicle,agent.address,agent.img_url,agent.category,agent.status,agent.login_status,vehicle.id AS vehicle_id,vehicle.name AS vehicle_name';
$this->db->select($data);
$this->db->from('agent');
$this->db->join('vehicle', 'agent.vehicle=vehicle.id');
return $this->db->get()->result_array();
}
View:
<?php foreach ($result as $value): ?>
<div class="col-md-4 col-sm-4 col-xs-12 profile_details">
<div class="well profile_view">
<div class="col-sm-12">
<h4 class="brief"><i>Digital Strategist</i></h4>
<div class="left col-xs-7">
<p><i class="fa fa-user"></i> Name: <?= $value['name']; ?></p>
<ul class="list-unstyled">
<li><i class="fa fa-building"></i> Vehicle: <?= $value['vehicle_name']; ?></li>
<li><i class="fa fa-phone"></i> Mobile: <?= $value['mobile']; ?> </li><br/>
<div class="onoffswitch">
<input type="hidden" value="<?= $value["id"]; ?>"/>
<input type="checkbox" class="js-switch"
<?php if ($value['status'] == 1) {
echo "checked";
} ?>>
</div>
</ul>
</div>
<div class="right col-xs-5 text-center">
<img src="/<?= $value['img_url']; ?>" alt="" class="img-circle img-responsive" style="height: 120px; width: 120px;">
</div>
</div>
<div class="col-xs-12 bottom text-center">
<div class="col-xs-12 col-sm-6 emphasis">
<p class="ratings">
<a>4.0</a>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star-o"></span>
</p>
</div>
<div class="col-xs-12 col-sm-6 emphasis btn-group">
<?php if ($value['status'] == 1): ?>
<i class="glyphicon glyphicon-pencil"> </i> Edit
<?php else: ?>
<i class="glyphicon glyphicon-pencil"> </i> Edit
<?php endif; ?>
<a href="<?= base_url("agent/detail/{$value['id']}"); ?>" class="btn btn-primary btn-xs">
<i class="fa fa-user"> </i> View Profile </a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
Below Screenshot:
Screenshot
MY Question: How to create pagination with letters in codeigniter.
MY Question: I create agent module and i apply pagination with letters in above Screenshot. so how to apply pagination with letters in above view.
I have a problem with upload images in Codeigniter, when I add a new image an error show ( You did not select a file to upload.) I dont know if miss something in my code
this my function controller:
public function upload_img(){
$this->load->model('esthetique_model');
$config['upload_path'] = realpath(APPPATH.'../upload');
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['max_size'] = '204800';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload()){
$error = array('error' => $this->upload->display_errors());
foreach ($error as $item => $value){
echo'<ol class="alert alert-danger"><li>'.$value.'</ol></li>';
}
exit;
}else{
$upload_data = $this->upload->data();
$path = $upload_data['file_name'];
$this->esthetique_model->photo_insert_mdl($path);
echo'<h4 style="color:green">Image uploaded Succesfully</h4>';
}
}
my view :
<?php echo form_open('esthetique/upload_img'); ?>
<div class="modal-body">
<!-- hidden input montinned with class sr-only -->
<div class="form-group"><label class="sr-only" =""></label>
<input type="text" name="idsc" class="sr-only" id="idsc" ></div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="userfile">Choisissez l'image</label>
<input type="file" name="userfile" id="userfile">
</div>
</div>
<div class="form-group">
<img id="loader" src="<?php echo base_url() ?>asset/images/486.GIF" style="height: 30px;">
</div>
<div class="form-group">
<img id="preview" src="#" style="height: 80px;border: 1px solid #DDC; " />
</div>
</div>
<div class="form-group ">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-calendar">
</i>
</div>
<input class="form-control" id="date" name="date" placeholder="Date" type="text"/>
</div>
</div>
<div class="form-group">
<textarea class="form-control" row="3" id="note" name="note" placeholder="Note"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
<button type="submit" class="btn btn-primary">Enregistrer</button>
</div>
<?php echo form_close(); ?>
</div>
</div>
</div>
thanks for helping
Try the following (specifying the file input name in your controller):
...
if ( ! $this->upload->do_upload('userfile')) {
...
More information that may be useful: http://www.codeigniter.com/user_guide/libraries/file_uploading.html
I have changed in view
<?php echo form_open('esthetique/upload_img'); ?>
by
<?php echo form_open_multipart('esthetique/upload_img'); ?>
its work now