How Can I Get Admin Id and Use it across the application? - php

In codeigniter I want to add the product on admin Id which is required in DB Table. when Admin log in his ID must be catch. whenever and where Id is needed it must be available.
here is my VIEW in which
<?php echo form_open_multipart('admin/add_product');?>
<!------------------Product Name------------------------>
<div class="row form-group">
<div class="col-sm-10">
<label>Product Name: *</label>
<?php echo form_input(['name'=>'name','class'=>'form-
control','placeholder'=>'Product name..','value'=>
set_value('name')])?>
<div>
<?php echo form_error('name');?>
</div>
</div></div>
<!------------------Product Cat---------------------------->
<div class="row form-group">
<div class="col-sm-12">
<label>Category: *</label> <br>
<select class="selectpicker" name="pro_cat_id">
<option label="Select Category">Category</option>
<?php
foreach($product_cat as $cat)
{?>
<option value="<?= $cat['pro_cat_id'] ?>"><?= $cat['category'] ?>
</option>
<?php }?>
</select>
<div>
<!------------------Product Price---------------------------->
<div class="row form-group">
<div class="col-md-10">
<label>Product Price: *</label>
<?php echo form_input(['name'=>'price','class'=>'form-
control','placeholder'=>'Product Price..','value'=>
set_value('price')])?>
<div>
<?php echo form_error('price');?>
</div>
</div></div>
<!------------------Product Location---------------------------->
<div class="row form-group">
<div class="col-md-10">
<label>Product Location: *</label>
<?php //echo form_input(['name'=>'location','class'=>'form-
control','placeholder'=>'Product Location'])?>
</div></div>
</div></div>
<!-----------End of body---------------->
</div>
<div class="modal-footer">
<input name="" type="submit" value="ADD" class="btn btn-success">
</div>
<?php echo form_close();?>
</div>
</div>
</div>
Here is my Controller
function add_product(){
$data['product_size'] = $this->show->show_product_size();
$data['product_cat']= $this->show->show_product_category();
$data['product_color'] = $this->show->show_product_color();
$data['pr']= $this->show->show_provider();
$post= $this->input->post();
$ =this->form_validation->set_error_delimiters("<p class='text-danger'>","
</p>");
if($this->form_validation->run('add_product')){
if($this->add->add_product($post)==TRUE){
$this->db->close();
$this->session->set_flashdata('success','Product has been added
successfully');
return redirect('admins/pages/add_product_page');
//$this->load->admin_template('admin/add_product',$data);
}
}
else
{
$this->session->set_flashdata('failled','Sorry, fail to add product');
//return redirect('admins/pages/add_product_page');
$upload_error= $this->upload->display_errors();
$this->load->admin_template('admin/add_product',$data);
}
}

Use this query, preferably in your controller:
$this->session->userdata('id');

Related

using Session ID to order something

So I am making a project where you can order food at school cafeteria, I already have a project where you can make a order with the menu and the student, and time.
But now I want that the student can order at it's own and not select any student so for the order it takes the currently logged in student. Sorry for bad english and thanks for every answer, i appreciate it.
[enter image description here](https://i.stack.imgur.com/NFz6G.png)
So Schueler is student and Menu is menu
uhrzeit is time
Now I want that there is no student to select, it takes the session id to make a order.
This is my order/create.php file
<?php
$title = "Menü reservieren";
include '../layouts/top.php';
session_start();
if(!isset($_SESSION['schuelerid'])) {
die('Bitte zuerst einloggen');
}
//Abfrage der Nutzer ID vom Login
$userid = $_SESSION['schuelerid'];
$email = $_SESSION['email'];
echo "Hallo Schueler: ".$userid;
echo " ".$email;
require_once('../../models/Bestellungen.php');
// create new/empty model, contains all input-values and error-messages
$r = new Bestellungen();
if (!empty($_POST)) {
$r->setMenu(isset($_POST['menu']) ? $_POST['menu'] : '');
$r->setUhrzeit(isset($_POST['uhrzeit']) ? $_POST['uhrzeit'] : 0);
$r->setSchueler(isset($_POST['schueler']) ? $_POST['schueler'] : 0);
// redirect to view-page after successfull saving
if ($r->save()) {
header("Location: view.php?id=" . $r->getId());
exit();
}
}
?>
<div class="container">
<div class="row">
<h2><?= $title ?></h2>
</div>
<form class="form-horizontal" action="create.php" method="post">
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-2">
<div class="form-group required">
<label class="control-label">Schueler *</label>
<select style="width: 200px" name="schueler">
<option selected></option>
<?php
require_once "../../models/Schueler.php";
foreach (Schueler::getAll() as $g){
?>
<option value='<?=$g->getId()?>'><?=$g->getName()?></option>
<?php
}
?>
</select>
<?php if (!empty($r->getErrors()['schueler'])): ?>
<div class="help-block"><?= $r->getErrors()['schueler'] ?></div>
<?php endif; ?>
</div>
</div>
<div class="col-md-2">
<div class="form-group required ">
<label class="control-label">Menu *</label>
<select name="menu" style="width: 200px">
<option selected></option>
<?php
require_once "../../models/Menu.php";
foreach (Menu::getAll() as $z){
?>
<option value='<?=$z->getId()?>'><?=$z->getName()?></option>
<?php
}
?>
</select>
<?php if (!empty($r->getErrors()['menu'])): ?>
<div class="help-block"><?= $r->getErrors()['menu'] ?></div>
<?php endif; ?>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">
<div class="form-group required ">
<label class="control-label">Uhrzeit *</label>
<input type="datetime-local" class="form-control" name="uhrzeit" value="">
<?php if (!empty($r->getErrors()['uhrzeit'])): ?>
<div class="help-block"><?= $r->getErrors()['uhrzeit'] ?></div>
<?php endif; ?>
</div>
</div>
<div class="col-md-1"></div>
</div>
<div class="row">
<div class="form-group">
<button type="submit" name="submit" class="btn btn-success">Erstellen</button>
<a class="btn btn-default" href="view.php">Abbruch</a>
</div>
</div>
</form>
</div> <!-- /container -->
<?php
include '../layouts/bottom.php';
?>

Laravel 8 throws undefined offset how to handle it?

here I have form to retrieve data from database using date and time issue is iam able to retrive data succesfuly most times but some time i get this error
here is the code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\PricingDetail;
use App\AccessoryCharge;
use App\Discount;
use App\MonthlyCourtCharge;
class PricingDetailController extends Controller
{
public function index(Request $request){
$op_id=$request->session()->get('op_id');
$inf_id=$request->session()->get('inf_id');
if(is_null($inf_id)){
return redirect('/infrastructure_details');
}else if(is_null($op_id)){
return redirect('/operational_details');
}else{
$timings=DB::table('operational_details')
->select('opening_time','closing_time')
->where('infrastructure_details_id',$inf_id)
->first();
$pricing_details=[];
$pricing_details=DB::table('pricing_details')
->where('infrastructure_details_id','=',$inf_id)
->get();
$accessory_charges=[];
$accessory_charges=DB::table('accessory_charges')
->where('infrastructure_details_id','=',$inf_id)
->get();
$discounts=[];
$discounts=DB::table('discounts')
->where('infrastructure_details_id','=',$inf_id)
->get();
$monthly_charges=[];
$monthly_charges=DB::table('monthly_court_charges')
->where('infrastructure_details_id','=',$inf_id)
->get();
if(($pricing_details->count())>0){
$request->session()->put('price_id',$pricing_details[0]->id);
}
return view('pricing_details',['inf_id'=>$inf_id,'op_id'=>$op_id,'timings'=>$timings,'pricing_details'=>$pricing_details,'acc_charges'=>$accessory_charges,'discounts'=>$discounts,'monthly_charges'=>$monthly_charges]);
}
//return view('pricing_details',['timings'=>$timings]);
//return view('home',['court_types'=>$court_types]);
}
public function create(Request $request){
$diff=$request->input('diff');
$no_accessories=$request->input('no_accessories');
$no_discounts=$request->input('no_discounts');
$no_monthly_charges=$request->input('no_monthly_charges');
for($i=0;$i<$diff;$i++){
$pricing_details=new PricingDetail;
$pricing_details->timings=$request->input('time'.$i);
$pricing_details->price=$request->input('price'.$i);
$pricing_details->discount=$request->input('discount'.$i);
$pricing_details->discounted_price=$request->input('discounted_price'.$i);
$pricing_details->disc_from_date=$request->input('disc_from_date'.$i);
$pricing_details->disc_to_date=$request->input('disc_to_date'.$i);
$pricing_details->infrastructure_details_id=$request->input('inf_id');
$pricing_details->operational_details_id=$request->input('op_id');
$pricing_details->day_types_id=$request->input('day_type'.$i);
$pricing_details->save();
}
for($i=1;$i<=$no_accessories;$i++){
$accessory_charge=new AccessoryCharge;
$accessory_charge->item=ucfirst($request->input('item'.$i));
$accessory_charge->brand=ucfirst($request->input('brand'.$i));
$accessory_charge->price=$request->input('acc_price'.$i);
$accessory_charge->quantity=$request->input('quantity'.$i);
$accessory_charge->return_type=$request->input('return_type'.$i);
$accessory_charge->infrastructure_details_id=$request->input('inf_id');
$accessory_charge->operational_details_id=$request->input('op_id');
$accessory_charge->save();
}
for($i=1;$i<=$no_monthly_charges;$i++){
$monthly_charge=new MonthlyCourtCharge;
$monthly_charge->infrastructure_details_id=$request->input('inf_id');
$no_days=0;
$scheme_type=$request->input('scheme_type'.$i);
if($scheme_type=="scheme1"){
$no_days=22;
}else{
$no_days=31;
}
$monthly_charge->scheme_type=$scheme_type;
$monthly_charge->no_days=$no_days;
$monthly_charge->hour_type=$request->input('hour_type'.$i);
$monthly_charge->from_time=date('H:i',strtotime($request->input('from_time'.$i)));
$monthly_charge->to_time=date('H:i',strtotime($request->input('to_time'.$i)));
$monthly_charge->price=$request->input('price'.$i);
$monthly_charge->save();
}
$id=$pricing_details->id;
$request->session()->put('price_id', $id);
return redirect('/facility_details');
}
public function update(Request $request){
$diff=$request->input('diff');
$no_accessories=$request->input('no_accessories');
//$no_discounts=$request->input('no_discounts');
$no_monthly_charges=$request->input('no_monthly_charges');
for($i=0;$i<$diff;$i++){
$pr_id=$request->input('pricing_id'.$i);
$pricing_details=PricingDetail::find($pr_id);
$pricing_details->timings=$request->input('time'.$i);
$pricing_details->price=$request->input('price'.$i);
$pricing_details->discount=$request->input('discount'.$i);
$pricing_details->discounted_price=$request->input('discounted_price'.$i);
$pricing_details->disc_from_date=$request->input('disc_from_date'.$i);
$pricing_details->disc_to_date=$request->input('disc_to_date'.$i);
$pricing_details->infrastructure_details_id=$request->input('inf_id');
$pricing_details->operational_details_id=$request->input('op_id');
$pricing_details->day_types_id=$request->input('day_type'.$i);
$pricing_details->save();
}
for($i=1;$i<=$no_accessories;$i++){
$acc_id=$request->input('acc_id'.$i);
$accessory_charge=AccessoryCharge::find($acc_id);
$accessory_charge->item=ucfirst($request->input('item'.$i));
$accessory_charge->brand=ucfirst($request->input('brand'.$i));
$accessory_charge->price=$request->input('acc_price'.$i);
$accessory_charge->quantity=$request->input('quantity'.$i);
$accessory_charge->return_type=$request->input('return_type'.$i);
$accessory_charge->infrastructure_details_id=$request->input('inf_id');
$accessory_charge->operational_details_id=$request->input('op_id');
$accessory_charge->save();
}
for($i=1;$i<=$no_monthly_charges;$i++){
$monthly_id=$request->input('monthly_id'.$i);
$monthly_charge=MonthlyCourtCharge::find($monthly_id);
//$monthly_charge->infrastructure_details_id=$request->input('inf_id');
$no_days=0;
$scheme_type=$request->input('scheme_type'.$i);
if($scheme_type=="scheme1"){
$no_days=22;
}else{
$no_days=31;
}
$monthly_charge->scheme_type=$scheme_type;
$monthly_charge->no_days=$no_days;
$monthly_charge->hour_type=$request->input('hour_type'.$i);
$monthly_charge->from_time=date('H:i',strtotime($request->input('from_time'.$i)));
$monthly_charge->to_time=date('H:i',strtotime($request->input('to_time'.$i)));
$monthly_charge->price=$request->input('price'.$i);
$monthly_charge->save();
}
$id=$pricing_details->id;
$request->session()->put('price_id', $id);
return redirect('/facility_details');
}
}
here is the layout code
<div class="dynamic_row2">
<div class="row">
<div class="col-md-12 bg-info text-white">
<h4 calss="h4-responsive">4. Monthly Charges</h4>
</div>
</div>
<div class="row">
<div class="col-md-2">
<h4 class="h4-responsive">Scheme Type</h4>
</div>
<div class="col-md-2">
<h4 class="h4-responsive">Hour Type</h4>
</div>
<div class="col-md-3">
<h4 class="h4-responsive">From Time</h4>
</div>
<div class="col-md-3">
<h4 class="h4-responsive">To Time</h4>
</div>
<div class="col-md-2">
<h4 class="h4-responsive">Price / hour</h4>
</div>
</div>
#php
$i=1;
#endphp
#foreach($monthly_charges as $monthly)
{{Form::hidden('monthly_id'.$i,$monthly->id)}}
<div class="row" id="discount_row1">
<div class="col-md-2">
<div class="form-group">
<select name="scheme_type<?php echo $i; ?>" class="form-control" required>
<option value="<?php echo $monthly->scheme_type; ?>" selected><?php echo $monthly->scheme_type; ?></option>
<option value="" disabled>Select Scheme</option>
<option value="scheme1">Scheme1 - 22 days</option>
<option value="scheme2">Scheme2 - 30/31 days</option>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<select name="hour_type<?php echo $i; ?>" class="form-control" required>
<option value="<?php echo $monthly->hour_type; ?>" selected><?php echo $monthly->hour_type; ?></option>
<option value="" disabled>Select hour type</option>
<option value="Peak hour">Peak hour</option>
<option value="NonPeak hour">NonPeak hour</option>
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
{{ Form::time('from_time'.$i,$monthly->from_time,['class'=>'form-control','placeholder'=>'From Time','required']) }}
</div>
</div>
<div class="col-md-3">
<div class="form-group">
{{ Form::time('to_time'.$i,$monthly->to_time,['class'=>'form-control','placeholder'=>'From Time','required']) }}
</div>
</div>
<div class="col-md-2">
<div class="form-group">
{{ Form::number('price'.$i++,$monthly->price,['class'=>'form-control','placeholder'=>'From Time','required']) }}
</div>
</div>
</div>
#endforeach
</div>
{{Form::submit('Update',['class'=>'btn btn-primary'])}}
{!! Form::close() !!}
#endif
i have checked database datatypes since i works most of the time no problem there. i don't what iam missing

How to create dependent drop down in Yii2 using Activeform?

i have form in which there are 2 dropdowns which are select batch from first dropdown and according to that batch, students will appear in second dropdown , Right now i am getting dropdown of batch but, not getting dropdown of students using batch
This is my view
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use common\models\TblBetch;
use common\models\TblCompany;
use common\models\TblCourse;
use common\models\TblStudent;
use common\models\TblStudentExpence;
use kartik\widgets\DepDrop;
use yii\db\Query;?><link rel="shortcut icon" href="<?php echo Yii::$app->params['global_theme_path'];?>images/logo1.png" type="image/png"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><script src="http://iamrohit.in/lab/js/location.js"></script><div class="pageheader"><h2><i class="fa fa-money"></i>Expense</h2>
<div class="breadcrumb-wrapper">
<span class="label">You are here:</span>
<ol class="breadcrumb">
<li>Westline Shipping</li>
<li class="active">Add Expense</li>
</ol></div></div><div class="contentpanel">
<?php
$session = Yii::$app->session;
if($session->hasFlash('success'))
{
echo $session->getFlash('success');
}
if($session->hasFlash('error'))
{
echo $session->getFlash('error');
}
$site = '';
?>
<div class="row">
<div class="col-md-12">
<div class="container-fluid-50">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-btns">
−
</div>
<h4 class="panel-title">Add Expense</h4>
</div>
<form class="panel-body" action="dashboard" method="post">
<div class="row">
<?php $form = ActiveForm::begin(); ?>
<div class="col-sm-9">
<div class="form-group">
<label class="control-label"></label>
<?php
//$batch = new TblBetch();
//$quer = new Query();
//$getid = [''];
//$getid = $quer->select('b_sn')->from($batch->tableName())->all();
//echo $form->field($model,'se_b_id')->dropDownList($getid,['id'=>'se_b_id']);
?>
<?=
$form->field($model,'se_s_id')->dropDownList(
ArrayHelper::map(TblBetch::find()->all(),'b_id','b_sn'),
[
'prompt'=>'Select Batch',
'name'=>'s_b_id',
'id'=>'s_b_id',
'onchange'=>'$.post("student?id="+$(this).val(),function(data){$("select#tblstudentexpence-se_s_id").html(data);});'
]);
?>
</div>
</div><!-- col-sm-6 -->
<div class="col-sm-9">
<div class="form-group">
<label class="control-label"></label>
<?=
$form->field($model,'se_s_id')->dropDownList(
ArrayHelper::map(TblStudent::find()->all(),'s_id','s_fname'),
[
'prompt'=>'Select Student',
'name'=>'se_s_id',
'id'=>'se_s_id'
]);
?>
</div>
</div><!-- col-sm-6 -->
<div class="col-sm-9">
<div class="form-group">
<label class="control-label">Payment Mode</label>
<div class="radio"><label><input type="radio" name="num" value="cash" required> Cash </label></div>
<div class="radio"><label><input type="radio" name="num" value="check" required> Check </label></div>
<div class="radio"><label><input type="radio" name="num" value="dd" required> DD </label></div>
</div>
</div><!-- col-sm-6 -->
<div class="col-sm-9">
<div class="form-group">
<label class="control-label">Check / DD No</label>
<input type="text" name="num" id="num" class="form-control" placeholder="Enter your check or DD number" required/>
</div>
</div><!-- col-sm-6 -->
<div class="col-sm-9">
<div class="form-group">
<label class="control-label">Amount</label>
<input type="text" name="lastname" class="form-control" placeholder="Enter your Amount" required/>
</div>
</div><!-- col-sm-6 -->
<div class="col-sm-9">
<div class="form-group"> <br><br>
<input type="submit" value="Submit" class="btn btn-primary">
<input type="reset" value="Cancel" class="btn btn-primary">
</div></div>
</div><!-- row -->
</form>
</div><!-- panel-body -->
</div>
</div>
</div> <div class="col-md-12">
</div>
</div></div></div> <script>
$(function() {
window.invalidate_input = function() {
if ($('input[name=num]:checked').val() == "check" || $('input[name=num]:checked').val() == "dd")
$('#num').removeAttr('disabled');
else
$('#num').attr('disabled', 'disabled');
};
$("input[name=num]").change(invalidate_input);
invalidate_input();
});
This is my controller (sitecontroller.php)
public function actionStudent($id)
{
//p($id);
$student = new TblStudent();
$queryobj = new Query();
$data = [];
$data = $queryobj->select('*')->from($student->tableName())->where(['s_betch'=>$id])->count();
//p($data);
$queryobj1 = new Query();
$getid = [];
$getid = $queryobj->select('*')->from($student->tableName())->where(['s_betch'=>$id])->all();
//p($getid);
if($data > 0)
{
foreach($getid as $gid)
{
echo "<option value='".$gid->s_id."'>".$gid->s_fname."</option>";
}
}
else
{
echo "<option> - </option>";
}
}
I am getting this response in firebug after ajax call
You can implement dependent drop-down much simpler in yii 2 because there is a widget available which you can use.
use kartik widget here -> kartik dependent drop down

Codeigniter : Form became weird when using select option (form_dropdown) to edit my data

It's work fine when I am inputing data using select option on CI but when I try to edit or update my data again my form became weird like this (See picture edit form)
Here my controller :
public function updateobat ($kode_obat){
if($_POST==null){
$this->load->model('a_model');
$data['hasil'] = $this->a_model->select2($kode_obat);
$data['title'] = "Data Stok Obat | Praktik Dokter Umum";
$data['tb_jenisobat'] = $this->a_model->ambil_jenisobat();
$this->template->admin('admin/edit-obat',$data);
}else{
$this->load->model('a_model');
$this->a_model->update_obat($kode_obat);
$data['title'] = "Data Stok Obat | Praktik Dokter Umum";
$data['obat'] = $this->a_model->ambil_obat();
$this->template->admin('admin/data-obat',$data);
}
}
Model
public function update_obat($kode_obat){
$nama_obat = $this->input->post('nama_obat');
$kode_jenis_obat = $this->input->post('kode_jenis_obat');
$stok= $this->input->post('stok');
$data = array('nama_obat' => $nama_obat,
'kode_jenis_obat' => $kode_jenis_obat,
'stok' => $stok,
);
$this->db->where('kode_obat',$kode_obat);
$this->db->update('tb_obat',$data);
}
public function select2($kode_obat){
return $this->db->get_where('tb_obat', array('kode_obat' => $kode_obat))->row();
}
View
<!-- Main content -->
<section class="content">
<div class="row">
<!-- left column -->
<div class="col-md-8">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Silahkan melakukan edit stok obat</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form role="form" action="<?php echo base_url().'index.php/a_controller/updateobat/'.$hasil->kode_obat; ?>" method="post">
<div class="box-body">
<div class="form-group">
<label for="exampleInputNama">Nama Obat</label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-medkit"></i></span>
<input type="text" class="form-control" name="nama_obat" id="exampleInputNama" placeholder="Nama Obat" action="<?php echo form_input('nama_obat',$hasil->nama_obat);?>">
</div>
</div>
<div class="form-group">
<label for="exampleInputJenis">Jenis Obat</label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-list"></i></span>
<select name="kode_jenis_obat" class="form-control" action="<?php echo form_dropdown('kode_jenis_obat',$hasil->kode_jenis_obat);?>">
<option value="none" selected="selected">Pilih Jenis Obat</option>
<!-----Displaying fetched cities in options using foreach loop ---->
<?php foreach($tb_jenisobat as $jenisobat):?>
<option value="<?php echo $jenisobat->kode_jenis_obat?>"><?php echo $jenisobat->nama_jenis_obat?></option>
<?php endforeach;?>
</select>
</div>
</div>
<div class="form-group">
<label for="exampleInputUsername">Stok Obat</label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-list"></i></span>
<input type="text" class="form-control" name="stok" id="exampleInputUsername" placeholder="Stok" action="<?php echo form_input('stok',$hasil->stok);?>">
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
<!-- /.box -->
</div>
</div>
<!-- /.row -->
</section>
I am using form_dropdown for my select option
I think there is something wrong with my controller syntax?
$data['tb_jenisobat'] = $this->a_model->ambil_jenisobat();
But I am not sure enough, can someone help me?
Picture : edit form

Disallowed key character in codeigniter

I have a view page.i have to edit a list of values.bt after submit i have an error disallowed character key.I cant find it how this error occur.
view
foreach($track_details->result() as $name) { ?>
<form class="form-horizontal" method="post" id="income_edit" action="<?php echo base_url();?>income_list_cntrl/update_income" enctype="multipart/form-data">
<input type="text" name="track_id" value="<?php echo $track_id; ?>" >
<div class="control-group">
<label class="control-label">Income Name</label>
<div class="controls">
<input type="text" class="span6 m-wrap" value="<?echo $name->income_name?>" name="income_name" id="income_name" readonly>
<?php echo form_error('income_name'); ?>
</div>
</div>
<div class="control-group">
<label class="control-label">Income Amount</label>
<div class="controls">
<input type="text" class="span6 m-wrap" value="<?echo $name->income_amount?>" name="income_amount" id="income_amount" >
<?php echo form_error('income_amount'); ?>
</div>
</div>
<div class="control-group">
<label class="control-label">Crop Quantity</label>
<div class="controls">
<input type="text" class="span6 m-wrap" value="<?echo $name->crop_quantity?>" name=crop_quantity" id="crop_quantity" >
<?php echo form_error('crop_quantity'); ?>
</div>
</div>
<div class="control-group">
<label class="control-label">Per Rate</label>
<div class="controls">
<input type="text" class="span6 m-wrap" value="<?echo $name->per_rate?>" name=per_rate" id="per_rate" >
<?php echo form_error('per_rate'); ?>
</div>
</div>
<div class="control-group">
<label class="control-label">Choose a client</label>
<div class="controls">
<select class="span6 m-wrap" name="select_client" >
<? foreach ($client_details->result() as $var) { ?>
<option <?php if($name->client_id == $var->client_id) { ?> selected="selected" <? } ?> value="<?echo $var->client_id;?>"><?echo $var->client_name;?></option>
<?}?>
</select>
<?php echo form_error('select_client'); ?>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn green" id="Submit">Submit</button>
</form>
<?}?>
controller
After removing the crop quantity and per rate no error but dont edit it.
public function update_income(){
$this->form_validation->set_error_delimiters('<div style="color:#B94A48">', '</div>');
//$this->form_validation->set_rules('income_name', 'Income name', 'required');
$this->form_validation->set_rules('income_amount', 'Income Amount', 'required');
$this->form_validation->set_rules('crop_quantity', 'Crop Quantity', 'required');
$this->form_validation->set_rules('per_rate', 'Per Rate', 'required');
$this->form_validation->set_rules('select_client', 'Client Name', 'required');
if ( $this -> form_validation -> run() === FALSE ){
$this->index();
} else {
$track_id=$this->input->post('track_id');
$income_name=$this->input->post('income_name');
$income_amount=$this->input->post('income_amount');
$crop_quantity=$this->input->post('crop_quantity');
$per_rate=$this->input->post('per_rate');
$client_name=$this->input->post('select_client');
$this->load->model('income_edit_model');
$data = array(
'income_name'=>$income_name,
'income_amount'=>$income_amount,
'crop_quantity'=>$crop_quantity,
'per_rate'=>$per_rate,
'client_name'=>$client_name,
);
$result=$this->income_edit_model->update_track_income($data,$track_id);
// redirect(base_url().'income', 'refresh');
}
}
Two problems:
First: Missing <?php open tags. Look through this and change <? to <?php
<select class="span6 m-wrap" name="select_client" >
<? foreach ($client_details->result() as $var) { ?>
<option <?php if($name->client_id == $var->client_id) { ?> selected="selected" <? } ?> value="<?echo $var->client_id;?>"><?echo $var->client_name;?></option>
<? } ?>
</select>
Second: Missing closing </div
<div class="form-actions">
<button type="submit" class="btn green" id="Submit">Submit</button>
<!-- MISSING </div> HERE -->
</form>

Categories