Column 'username' cannot be null - codeigniter

I wonder why there is this error message appearing. Column 'username' cannot be null
?
I set Null to No.
A Database Error Occurred
Error Number: 1048
Column 'username' cannot be null
INSERT INTO login (username, email, password, role) VALUES
(NULL, NULL,
'$2y$10$FaVW7V1yEDB0NnlmgwPHQ.SQi34ZCXi9ABJDOebDflZ.cqcSwZAoW', NULL)
Filename: C:/Program
Files/EasyPHP-Devserver-16.1/eds-www/companygiondaci/system/database/DB_driver.php
Line Number: 691
views/addusers.php
<div class="row-fluid">
<div class="span12">
<?php $this->load->library('form_validation'); ?>
<?php echo $successmessage; ?>
<?php echo validation_errors(); ?>
<?php echo form_open('cpages/addusersdb'); ?>
<div class="widget-box">
<div class="widget-title"><h5>Add User</h5></div>
<div class="widget-content">
<table border="0" style="width: 100%; height: 90px;">
<tr>
<td>USERNAME</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>EMAIL</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>ROLE</td>
<td><?php echo form_dropdown('roles', $options, 'administrator'); ?></td>
</tr>
<tr>
<td></td>
<td><input type="submit" class="edit" value="ADD"></td>
</tr>
</table>
</div>
</div>
</div>
</div>
models/Mpages.php
public function add_user()
{
$options = [
'roles' => 'administrator',
];
$hash = password_hash($this->input->post('password'), PASSWORD_BCRYPT, $options);
$data = array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $hash,
'role' => $this->input->post('roles')
);
return $this->db->insert('login', $data);
}

if($this->input->post()) {
$hash = password_hash($this->input->post('password'), PASSWORD_BCRYPT, $options);
$data = array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $hash,
'role' => $this->input->post('roles')
);
$this->YOUR_MODEL->add_user($data);
}
This should go into your controller.
And your model function should be like this
public function add_user($data)
{
return $this->db->insert('login', $data);
}

Related

Form Validation on Array name fields - Codeigniter

I have a dynamic form to add rows. The form lets the users to add transactions and submit it. I want to validate only the transaction numbers before inserting them into DB. I have to check
If the transaction field is empty or not
If the transaction already exists in the transactions table (if yes : display message transaction already exists. Please remove row. If no: proceed to DB insertion)
View part:
<div class="row">
<div class="col-md-12 ">
<?php echo validation_errors(); ?>
<?php
echo form_error("Transaction_number[]");
?>
<?php echo form_open('payment_refund/refund_form/'); ?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<table id='tbl' class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Transaction_number</th>
<th>Order_number</th>
<th>Amount_paid</th>
<th>Transaction_date</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type='text' name='Transaction_number[]' value="<?php echo set_value('Transaction_number[]'); ?>" /></td>
<td><input type='text' name='Order_number[]' value="<?php echo set_value('Order_number[]'); ?>" /></td>
<td><input type='number' name='Amount_paid[]' value="<?php echo set_value('Amount_paid[]'); ?>" /></td>
<td><input type='date' name='Transaction_date[]' value="<?php echo set_value('Transaction_date[]'); ?>" /></td>
<td><input type='button' value='Remove' class='rmv'></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan='3'><input type='button' value='+Add Row' id='add_row'></td>
</tr>
</tfoot>
</table>
<script>
$(document).ready(function(){
$("#add_row").click(function(){
var row="<tr> <td><input type='text' name='Transaction_number[]'></td> <td><input type='text' name='Order_number[]'></td> <td><input type='number' name='Amount_paid[]'></td> <td><input type='date' name='Transaction_date[]'></td> <td><input type='button' value='Remove' class='rmv'></td> </tr>";
$("#tbl tbody").append(row);
});
$("body").on("click",".rmv",function(){
$(this).closest("tr").remove();
});
});
</script>
<!-- Insert a check to see if any transaction details are entered before submit -->
<input type="submit" name="submit" id="submit" value="submit" class="btn btn-primary" >
<?php echo form_close(); ?>
</div>
Controller Part:
class Refund_form extends MY_Controller
{
public function __construct()
{
parent::__construct(array('stu'));
$this->load->model('payment_refund/refund_form_model','',TRUE);
}
public function index()
{
$this->load->helper('form');
$this->load->helper(array('form', 'url'));
$this->load->helper('array');
$this->load->library('form_validation');
$Transaction_number = $this->input->post('Transaction_number');
for($i = 0; $i < count($Transaction_number); $i++)
{
$tran = $Transaction_number[$i];
$this->load->library('form_validation');
$this->form_validation->set_rules($tran, 'Transaction', 'required');
}
if ($this->form_validation->run() == TRUE)
{
echo "All went well <br/>"; // insertion into DB for all table data fetched from view is done here
}
else
{
echo "All is NOT well <br/>";
}
public function add()
{
$this->drawHeader("Refund form - Add");
$this->load->view('payment_refund/refund_form_view');
$this->drawFooter();
}
Other methods that i tried to validate the form
`$formrules = array(
array(
'field' => 'Transaction_number[]',
'label' => 'the transsaction field',
'rules' => 'required'
),
);
$this->form_validation->set_rules($formrules);
if ($this->form_validation->run() == true)
{return true; } //DB insertion
else
{ return false; } `
DB insertion is done as below
for($i=0;$i<count($Transaction_number);$i++){
$data[] = [
'tracking_id' => $tracking_id,
'trans_id' => $Transaction_number[$i],
'order_id' => $Order_number[$i],
'amount' => $Amount_paid[$i],
'date_of_trans' => $Transaction_date[$i],
];
}
//inser_batch
$response=$this->db->insert_batch('refund_transaction_details',$data);
if($response==true){
echo "Records Saved Successfully";
}
else{
echo "Insert error !";
}

data is not submitting into db:laravel-5.8

I'm new to laravel and trying to save data into db but nothing happens. I just want to save it into db.
controller:
public function store(Request $request)
{
$request->validate([
'date' => 'required',
'start_time' => 'required',
'end_time' => 'required',
'time_slot' => 'required',
]);
Form::create(request(['date', 'start_time', 'end_time', 'time_slot']));
$data->save();
return view('form.index');
}
blade file:
<table class="table table-hover mt-5">
<thead>
<tr>
<th scope="col">Date</th>
<th scope="col">Start Time</th>
<th scope="col">End Time</th>
<th scope="col">Time Slice</th>
</tr>
</thead>
<tbody>
<tr>
<th>
<input type="date" name="date">
</th>
<td>
<input type="text" id="datetimepicker" name="start_time" />
</td>
<td>
<input type="text" id="datetimepicker" name="end_time" />
</td>
<td>
<select name="time_slot">
<option value="1">15 min</option>
<option value="2">30 min</option>
<option value="3">45 min</option>
<option value="4">1 hr</option>
</select>
</td>
</tr>
</tbody>
</table>
<button type="submit" type="button" class="btn btn-primary">Add Data</button>
I'm using resource route for it.
you have 2 options to save it in database:
1---------------------------
public function store(Request $request)
{
$request->validate([
'date' => 'required',
'start_time' => 'required',
'end_time' => 'required',
'time_slot' => 'required',
]);
$form = new Form(); //make new object from your model
$form->date = $request['date']; //each of the DB field fill with $request fields
$form->start_time = $request['start_time'];
$form->end_time = $request['end_time'];
$form->time_slot = $request'time_slot'];
$form->save(); //Save this to your DB
return view('form.index');
}
2-------------------------------Recomended
in this way you need to do something in your model
Model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Form extends Model
{
protected $table = "forms"; //table name in your DB
protected $fillable = ['date','start_date','end_date','time_slot']; //your fields in DB table that you want to fill them
}
Controller
public function store(Request $request)
{
$request->validate([
'date' => 'required',
'start_time' => 'required',
'end_time' => 'required',
'time_slot' => 'required',
]);
$form = new Form(); //make new object from your model
$form->create($request->all()); //NOTE:your fields in view should be the same name with your fields in DB, i mean for example you should get the start_date from an input that it's name is start_date, <input name="start_date">
return view('form.index');
}
i hope this helps you !
public function store(Request $request)
{
$request->validate([
'date' => 'required',
'start_time' => 'required',
'end_time' => 'required',
'time_slot' => 'required',
]);
Form::create($request->all());
return view('form.index');
}
blade file:
<form method="post" action="{{ route('form.store' }}">
{{ csrf_field() }}
<table class="table table-hover mt-5">
<thead>
<tr>
<th scope="col">Date</th>
<th scope="col">Start Time</th>
<th scope="col">End Time</th>
<th scope="col">Time Slice</th>
</tr>
</thead>
<tbody>
<tr>
<th>
<input type="date" name="date">
</th>
<td>
<input type="text" id="datetimepicker" name="start_time" />
</td>
<td>
<input type="text" id="datetimepicker" name="end_time" />
</td>
<td>
<select name="time_slot">
<option value="1">15 min</option>
<option value="2">30 min</option>
<option value="3">45 min</option>
<option value="4">1 hr</option>
</select>
</td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-primary">Add Data</button>
</form>

(laravel 5.7) what is the problem in this request !! validation done but data insertion is not happening as expected

First I'm sorry for my english.
I have a form with somme input and checkbox with dynamic id ,for example checkbox[] , input name="pointage_j[] ...
validation in the controller is done but insertion data in table not as expected, for example when pointage_j.1 = 1 and pointage_j.2 = 1 all insertion is done perfectly but when pointage_a.1 or pointage_2.1 all data insertion done with first id_employee . I can't understand where is my error !!
form :
#php
$nbr = count($employees);
#endphp
{{Form::hidden("nbr", $nbr)}}
<div class="form-group">
{{Form::label('date_pointage', 'Date du pointage')}}
{{Form::date('date_pointage', '', ['class' => 'form-control', 'placeholder' => 'Date du pointage'])}}
</div>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-1 align-middle" scope="col">N°</th>
<th class="col-md-2 align-middle">Nom Prénom</th>
<th class="col-md-1 align-middle" scope="col">Présence_J</th>
<th class="col-md-1 align-middle" scope="col">Présence_N</th>
<th class="col-md-1 align-middle" scope="col">Absence</th>
<th class="col-md-2 align-middle" scope="col">Heurs Sup</th>
</tr>
</thead>
<tbody>
#php $i = 0; #endphp
#foreach($employees as $employee)
#php $i = $i + 1; #endphp
<tr>
<th> #php echo $i ; #endphp</th>
<td>{{$employee ->nom_employee}} {{$employee ->prenom_employee}}</td>
<td>{{Form::checkbox("pointage_j[]", 1, 0,['id' => "pointage_j.$i"]) }}</td>
<td>{{Form::checkbox("pointage_n[]", 1, 0,['id' => "pointage_n.$i"]) }}</td>
<td>{{Form::checkbox("pointage_absence[]", 1, 0,['id' => "pointage_absence.$i"]) }}</td>
<td>{{Form::text("heur_sup[]", '0', ['class' => 'form-control','id'=>"heur_sup.$i"])}}</td>
{{Form::hidden("employee_id[]", $employee->id,['employee_id'=>"employee_id.$i"])}}
</tr>
#endforeach
</tbody>
</table>
<button type="submit" class="btn btn-primary mb-2">Enregistrer</button>
{!! Form::close() !!}
Store method in my controller :
public function store(Request $request)
{
$this->validate($request, [
'nbr' => 'required|integer',
'employee_id.*' => 'required|integer',
'date_pointage' => 'required|date',
'pointage_j.*' => 'accepted',
'pointage_n.*' => 'accepted',
'pointage_absence.*' => 'accepted',
'heur_sup.*' => 'nullable|integer|between:0,5',
]);
$nbr = $request->input('nbr');
for ($i = 0; $i < $nbr; $i++) {
if ($request->has("pointage_j.$i")) {
$pointage_j = 1;
} else {
$pointage_j = 0;
}
if ($request->has("pointage_n.$i")) {
$pointage_n = 1;
} else {
$pointage_n = 0;
}
if ($request->has("pointage_absence.$i")) {
$absence = 1;
} else {
$absence = 0;
}
$pointage = new Pointage;
$pointage->employee_id = $request->input("employee_id.$i");
$pointage->date_pointage = $request->input("date_pointage");
$pointage->jour_pointage = $pointage_j; //$request->has("pointage_j.$i") ? 1 : 0
$pointage->nuit_pointage = $pointage_n;
$pointage->absence_pointage = $absence;
$pointage->heurs_sup_pointage = $request->input("heur_sup.$i");
$pointage->save();
}
return redirect('/pointages')->with('success', 'Enregistrement reussi');
}
after a day of breaking my head, I found the solution.
I used an input field hidden before the chekbox and I used vanila javascript to change the value of the input hidden 0 by default and if the checkbox is checked the value changes to 1. in my controller I ignore the checkbox and I takes only the value of the hidden input.
just a note the hidden input must be before the checkbox without space or line break. I put the code of the view and the controller maybe it will be useful for someone.
my view create :
{!! Form::open(['action' =>'PointagesController#store', 'method' => 'POST']) !!}
#csrf
#php
$nbr = count($employees);
#endphp
{{Form::hidden("nbr", $nbr)}}
<div class="form-group">
{{Form::label('date_pointage', 'Date du pointage')}}
{{Form::date('date_pointage', '', ['class' => 'form-control', 'placeholder' => 'Date du pointage'])}}
</div>
<table class="table table-bordered" >
<thead>
<tr>
<th class="col-md-1 align-middle" scope="col">N°</th>
<th class="col-md-2 align-middle">Nom Prénom</th>
<th class="col-md-1 align-middle" scope="col">Présence_J</th>
<th class="col-md-1 align-middle" scope="col">Présence_N</th>
<th class="col-md-1 align-middle" scope="col">Absence</th>
<th class="col-md-2 align-middle" scope="col">Heurs Sup</th>
</tr>
</thead>
<tbody>
#php $i = 0; #endphp
#foreach($employees as $employee)
<tr>
<th colspan="1" width=30> {{$loop->iteration}}</th>
<td>{{$employee ->nom_employee}} {{$employee ->prenom_employee}}</td>
<td>{{Form::hidden("pointage_j_$i",0,['id' => "pointage_j_$i"])}}{{ Form::checkbox("pointage_j[]", 1, false,['onclick' => 'this.previousSibling.value=1-this.previousSibling.value'],['id' => "pointage_jj.$i"]) }}</td>
<td>{{Form::hidden("pointage_n_$i",0,['id' => "pointage_n_$i"])}}{{ Form::checkbox("pointage_n[]", 1, false,['onclick' => 'this.previousSibling.value=1-this.previousSibling.value'],['id' => "pointage_nn.$i"]) }}</td>
<td>{{Form::hidden("pointage_absence_$i",0,['id' => "pointage_absence_$i"])}}{{ Form::checkbox("pointage_absence[]", 1, false,['onclick' => 'this.previousSibling.value=1-this.previousSibling.value'],['id' => "pointage_absencee.$i"]) }}</td>
<td>{{Form::text("heur_sup[]", '0', ['class' => 'form-control','id'=>"heur_sup.$i"])}}</td>
{{Form::hidden("employee_id[]", $employee->id,['employee_id'=>"employee_id.$i"])}}
</tr>
#php $i = $i + 1; #endphp
#endforeach
</tbody>
</table>
<button type="submit" class="btn btn-primary mb-2" >Enregistrer</button>
{!! Form::close() !!}
my controller :
public function store(Request $request)
{
$this->validate($request,[
'nbr'=>'required|integer',
'employee_id.*'=>'required|integer',
'date_pointage'=>'required|date',
'pointage_j.*'=>'required|integer|between:0,1',
'pointage_n.*'=>'required|integer|between:0,1',
'pointage_absence.*'=>'required|integer|between:0,1',
'heur_sup.*'=>'nullable|integer|between:0,5',
]);
// dd($request->all());
$nbr=$request->input('nbr');
$i=0;
while ($i < $nbr){
$pointage = new Pointage;
$pointage-> employee_id = $request->input("employee_id.$i");
$pointage-> date_pointage = $request->input("date_pointage");
$pointage-> jour_pointage = $request->input("pointage_j_$i");
$pointage-> nuit_pointage = $request->input("pointage_n_$i");
$pointage-> absence_pointage = $request->input("pointage_absence_$i");
$pointage-> heurs_sup_pointage = $request->input("heur_sup.$i");
$pointage-> save();
$i++;
}
return redirect('/pointages')->with('success','Enregistrement reussi');
}

how can I add multiple rows in database from a single form?

I'm setting up a roster web application using Laravel, and I need a form where to input all the fields and then store them to the database, everything works fine when I use tinker or if I submit a single row, but when I try to submit the whole form only the last row is read.
this is the rota.blade.php file
{!! Form::open(['action' => 'RotaController#store', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th scope="row">Name</th>
<th scope="row">Sunday</th>
<th scope="row">Monday</th>
<th scope="row">Tuesday</th>
<th scope="row">Wednesday</th>
<th scope="row">Thursday</th>
<th scope="row">Friday</th>
<th scope="row">Saturday</th>
</tr>
</thead>
<tbody>
<!--
* create a loop to iterate through each instance in the weekly rota database
* and create a row for each one; in case the username coincides with the name in the rota
* add class="active" to each row, so it is easier for the user to identify its own row
-->
#csrf
#foreach ($users as $user)
<tr>
<th scope="row">
{{$user->first_name}}
<input name="user_id" type="hidden" value="{{$user->id}}">
<input name="week_no" type="hidden" value="{{$currWeek}}">
</th>
<th scope="row">
{{Form::text('sunday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('monday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('tuesday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('wednesday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('thursday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('friday', '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('saturday', '', ['class' => 'form-control'])}}
</th>
</tr>
#endforeach
{{Form::submit('Submit', ['class' => 'btn btn-primary'])}}
</tbody>
</table>
{!! Form::close() !!}
and this is RotaController#store:
public function store(Request $request)
{
//validation
$this->validate($request,[
'user_id' => 'required',
'sunday' => 'required',
'monday'=> 'required',
'tuesday'=> 'required',
'wednesday'=> 'required',
'thursday'=> 'required',
'friday'=> 'required',
'saturday'=> 'required',
'week_no'=> 'required'
]);
//create a field
$rota = new Rota;
$rota->user_id = $request->input('user_id');
$rota->week_no = $request->input('week_no');
$rota->sunday = $request->input('sunday');
$rota->monday = $request->input('monday');
$rota->tuesday = $request->input('tuesday');
$rota->wednesday = $request->input('wednesday');
$rota->thursday = $request->input('thursday');
$rota->friday = $request->input('friday');
$rota->saturday = $request->input('saturday');
$rota->save();
$users = DB::table('users')->orderBy('first_name', 'asc')->get();
return view('admin.admin-rota')->with('users', $users);
}
I tried dd($request) and it actually gets only the last set of input fields,
I guess I have to loop through them but I don't know how. Does anyone have any suggestion on what to try? thanks a lot for any feedback, I'm still very new using this framework.
I would group form data by users.
#foreach ($users as $user)
<tr>
<th scope="row">
{{$user->first_name}}
<input name="users[{{$user->id}}][id]" type="hidden" value="{{$user->id}}">
<input name="users[{{$user->id}}][week_no]" type="hidden" value="{{$currWeek}}">
</th>
<th scope="row">
{{Form::text("users[$user->id][sunday]", '', ['class' => 'form-control'])}}
<th scope="row">
{{Form::text("users[$user->id][monday]", '', ['class' => 'form-control'])}}
</tr>
#endforeach
{{Form::submit('Submit', ['class' => 'btn btn-primary'])}}
</tbody>
in the controller you will have array with data for each user.
Then your controller may look like this:
public function store(Request $request)
{
//validation
$this->validate($request,[
'users.*.user_id' => 'required',
'users.*.sunday' => 'required',
...
]);
foreach($request->get('users') as $userData){
$rota = new Rota;
$rota->user_id = $userData['user_id'];
$rota->week_no = $userData['week_no'];
$rota->sunday = $userData['sunday'];
...
$rota->save();
}
//create a field
$users = DB::table('users')->orderBy('first_name', 'asc')->get();
return view('admin.admin-rota')->with('users', $users);
}
You can append an index to each of the input's name, and hold a hidden input to store the collection count.
#php
$idx = 0;
#endphp
#foreach ($users as $user)
<tr>
<th scope="row">
{{$user->first_name}}
<input name="user_id_{{$idx}}" type="hidden" value="{{$user->id}}">
<input name="week_no_{{$idx}}" type="hidden" value="{{$currWeek}}">
</th>
<th scope="row">
{{Form::text('sunday_' . $idx , '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('monday_' . $idx, '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('tuesday_' . $idx, '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('wednesday_' . $idx, '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('thursday_' . $idx, '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('friday_' . $idx, '', ['class' => 'form-control'])}}
</th>
<th scope="row">
{{Form::text('saturday_' . $idx, '', ['class' => 'form-control'])}}
</th>
#php
$idx++;
#endphp
</tr>
#endforeach
{{-- holds numbers of users count --}}
<input type="hidden" name="user_count" value="{{$users->count()}}">
In the controller, loop over the amount of user's using variable $user_count that we got from blade file. Each data variable will have the appended index, and you can then correspond the right data that you entered from blade file. Note that the validation here is being done on each object per iteration. If you would like to VALIDATE ALL data before saving, make another foreach with the validate before saving the data.
for ($i=0; $i < $request->user_count; $i++) {
//validation
$this->validate($request,[
'user_id_' . $i => 'required',
'sunday_' . $i => 'required',
'monday_' . $i=> 'required',
'tuesday_' . $i => 'required',
'wednesday_' . $i=> 'required',
'thursday_' . $i => 'required',
'friday_' . $i=> 'required',
'saturday_' . $i=> 'required',
'week_no_' . $i=> 'required'
]);
//create a field
$rota = new Rota;
$rota->user_id_{$i} = $request->input('user_id_' . $i);
$rota->week_no_{$i} = $request->input('week_no_' . $i);
$rota->sunday_{$i} = $request->input('sunday_' . $i);
$rota->monday_{$i} = $request->input('monday_' . $i);
$rota->tuesday_{$i} = $request->input('tuesday_' . $i);
$rota->wednesday_{$i} = $request->input('wednesday_' . $i);
$rota->thursday_{$i} = $request->input('thursday_' . $i);
$rota->friday_{$i} = $request->input('friday_' . $i);
$rota->saturday_{$i} = $request->input('saturday_' . $i);
$rota->save();
}

I want to SAVE DATA into my sql using codeigniter, but when I click the submit button,it shows error page cannot be found

I want to SAVE DATA into my sql using codeigniter, but when I click the
submit button,it shows error page cannot be found ....the view file shows but on click on submit button it shows error on next page.........
my view file
add.php
<html>
<head>
<title>Insert Employee Records in Database</title>
</head>
<body>
<form action="<?php echo base_url('emp_add/save'); ?>" method="post">
<table align="center">
<tr>
<td>First Name:</td>
<td><?php echo form_input(array('id'=>'fname', 'name'=>'fname',
'placeholder' => 'First Name', 'size'=>25));?></td>
</tr>
<tr>
<td>Last Name:</td>
<td><?php echo form_input(array('id'=>'lname', 'name'=>'lname',
'placeholder' => '
<tr>lname', 'size'=>25));?></td>
</tr>
<td>Email:</td>
<td><?php echo form_input(array('id'=>'email', 'name'=>'email',
'placeholder' => 'Email', 'size'=>25));?></td>
</tr>
<tr>
<td>Credits:</td>
<td><?php echo form_input(array('id'=>'credits',
'name'=>'credits',
'placeholder' => 'credits', 'size'=>25));?></td>
</tr>
<tr>
<td></td>
<td><button type="submit" id="submit" name="submit" >ADD</button>
</td>
</tr>
</table>
</form>
</body>
</html>
my controller file
emp_addd.php
<?php class Emp_add extends CI_Controller {
public function_construct() {
parent:: _construct();
$this->load->model('employee_model');
$this->load->helper(array('form','url'));
}
public function index()
{
$this->load->view('add'); }
public function save() {
$this->load->model('employee_model');
if($this->input->post('submit'))
{
$this->employee_model->process();
}
redirect('emp_add');
}
my model file
employee_model.php
<?php if (!defined('BASEPATH')) exit('No direct script access
allowed'); class Employee_model extends CI_Model {
public function process()
{
$save = array(
'fname' => $this->input->post('fname'),
'lname' => $this->input->post('lname'),
'email' => $this->input->post('email'),
'credits' => $this->input->post('credits')
);
$this->db->insert('customers',$save);
}
} }
?>
SHOWING VIEW PAGE WELL. BUT ON SUBMIT IT SHOWS ERROR

Resources