cant upload file in mysql database using php codeigniter [duplicate] - php

This question already has answers here:
codeigniter upload file error
(2 answers)
Closed 8 years ago.
I want to upload a file in mysql database using php codeigniter. when I upload a file it don't show any error and file doesn't upload.and the value of column file_name in mysql shows as NULL.
Here is my view code :
<div class="box">
<div class="box-header"><span class="title"><?php echo get_phrase('diagnosis_report');?></span></div>
<div class="box-content">
<table cellpadding="0" cellspacing="0" border="0" class="table table-normal ">
<thead>
<tr>
<td><div>#</div></th>
<td><div><?php echo get_phrase('report_type');?></div></td>
<td><div><?php echo get_phrase('document_type');?></div></td>
<td><div><?php echo get_phrase('download');?></div></td>
<td><div><?php echo get_phrase('description');?></div></td>
<td><div><?php echo get_phrase('date');?></div></td>
<td><div><?php echo get_phrase('laboratorist');?></div></td>
<td><div><?php echo get_phrase('option');?></div></td>
</tr>
</thead>
<tbody>
<?php
$count = 1;
$diagnostic_reports = $this->db->get_where('diagnosis_report' , array('prescription_id' => $prescription_id))->result_array();
foreach($diagnostic_reports as $row2):?>
<tr>
<td><?php echo $count++;?></td>
<td><?php echo $row2['report_type'];?></td>
<td><?php echo $row2['document_type'];?></td>
<td style="text-align:center;">
<?php if($row2['document_type'] == 'image'):?>
<div id="thumbs">
<a href="<?php echo base_url();?>uploads/diagnosis_report/<?php echo $row2['file_name'];?>"
style="background-image:url(<?php echo base_url();?>uploads/diagnosis_report/<?php echo $row2['file_name'];?>)" title="<?php echo $row2['file_name'];?>">
</a></div>
<?php endif;?>
<a href="<?php echo base_url();?>uploads/diagnosis_report/<?php echo $row2['file_name'];?>" target="_blank"
class="btn btn-blue"> <i class="icon-download-alt"></i> <?php echo get_phrase('download');?></a>
</td>
<td><?php echo $row2['description'];?></td>
<td><?php echo date('d M,Y', $row2['timestamp']);?></td>
<td><?php echo $this->crud_model->get_type_name_by_id('laboratorist',$row2['laboratorist_id'],'name');?></td>
<td align="center">
<a href="<?php echo base_url();?>index.php?laboratorist/manage_prescription/delete_diagnosis_report/<?php echo $row2['diagnosis_report_id'];?>/<?php echo $prescription_id;?>" onclick="return confirm('delete?')"
rel="tooltip" data-placement="top" data-original-title="<?php echo get_phrase('delete');?>" class="btn btn-red">
<i class="icon-trash"></i>
</a>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
</div>
<!------DIAGNOSTIC REPORT FOR THIS PRESCRIPTION---->
<!------ADD A DIAGNOSTIC REPORT TO THIS PRESCRIPTION-->
<div class="box">
<div class="box-header"><span class="title"><?php echo get_phrase('add_diagnosis_report');?></span></div>
<div class="box-content">
<?php echo form_open('laboratorist/manage_prescription/create_diagnosis_report' , array('class' => 'form-horizontal validatable'));?>
<div class="padded">
<div class="control-group">
<label class="control-label"><?php echo get_phrase('report_type');?></label>
<div class="controls">
<input type="text" name="report_type" /> <span class="label label-blue">report type can be x-ray, blood-test etc.</span>
</div>
</div>
<div class="control-group">
<label class="control-label"><?php echo get_phrase('document_type');?></label>
<div class="controls">
<select name="document_type" >
<option value="image"><?php echo get_phrase('image');?></option>
<option value="doc" ><?php echo get_phrase('doc');?></option>
<option value="pdf"><?php echo get_phrase('pdf');?></option>
<option value="excel"><?php echo get_phrase('excel');?></option>
<option value="other"><?php echo get_phrase('other');?></option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label"><?php echo get_phrase('upload_document');?></label>
<div class="controls">
<input type="file" name="userfile" />
</div>
</div>
<div class="control-group">
<label class="control-label"><?php echo get_phrase('description');?></label>
<div class="controls">
<textarea name="description" ></textarea>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="hidden" name="prescription_id" value="<?php echo $prescription_id;?>" />
<button type="submit" class="btn btn-blue"><?php echo get_phrase('add_diagnosis_report');?></button>
</div>
</div>
</div>
</form>
</div>
</div>
and here is my code to upload file in database :
function manage_prescription($param1 = '', $param2 = '', $param3 = '')
{
if ($this->session->userdata('laboratorist_login') != 1)
redirect(base_url() . 'index.php?login', 'refresh');
if ($param1 == 'create_diagnosis_report') {
$data['report_type'] = $this->input->post('report_type');
$data['document_type'] = $this->input->post('document_type');
$data['prescription_id'] = $this->input->post('prescription_id');
$data['description'] = $this->input->post('description');
$data['timestamp'] = strtotime(date('Y-m-d') . ' ' . date('H:i:s'));
$data['laboratorist_id'] = $this->session->userdata('laboratorist_id');
move_uploaded_file($_FILES["userfile"]["tmp_name"] , "uploads/diagnosis_report/".$_FILES["userfile"]["name"]);
$data['file_name'] = $_FILES["userfile"]["name"];
$this->db->insert('diagnosis_report', $data);
$this->session->set_flashdata('flash_message', get_phrase('diagnosis_report_created'));
redirect(base_url() . 'index.php?laboratorist/manage_prescription/edit/' . $this->input->post('prescription_id'), 'refresh');
}
if ($param1 == 'delete_diagnosis_report') {
$this->db->where('diagnosis_report_id', $param2);
$this->db->delete('diagnosis_report');
$this->session->set_flashdata('flash_message', get_phrase('diagnosis_report_deleted'));
redirect(base_url() . 'index.php?laboratorist/manage_prescription/edit/' . $param3, 'refresh');
} else if ($param1 == 'edit') {
$page_data['edit_profile'] = $this->db->get_where('prescription', array(
'prescription_id' => $param2
))->result_array();
}
$page_data['page_name'] = 'manage_prescription';
$page_data['page_title'] = get_phrase('manage_prescription');
$page_data['prescriptions'] = $this->db->get('prescription')->result_array();
$this->load->view('index', $page_data);
}

You have to use form_open_multipart() not form_open() in your view file

Related

How to initiate if else statement inside a td tag

In my database, I have a table column that has a filepath for images. The filepath's name is photo Some of my rows don't have a filepath. Inside my while loop forshowing the table, I would like to add a condition that if there is no filepath, it would prompt the text "User did not upload a photo yet." and when it has filepath, I can show the filepath and link it with a target blank.
This is my php file for it.
<?php require_once 'process.php';
session_start();
$role = $_SESSION['sess_userrole'];
$name = $_SESSION['sess_name'];
if(!isset($_SESSION['sess_username']) && $role!="admin"){
header('Location: index.php?err=2');
}
?>
<html>
<head>
<title>User Accounts</title>
<link rel="icon" href="isalonlogo.png">
<link rel="stylesheet" href="css2/bootstrap.min.css">
<script src="css/jquery-3.3.1.slim.min.js"></script>
<script src="css/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="css/bootstrap.min.js"></script>
</head>
<body>
<?php
if (isset($_SESSION['message'])):?>
<div class="alert alert-<?=$_SESSION['msg_type']?>">
<?php
echo $_SESSION['message'];
unset ($_SESSION['message']);?>
</div>
<?php endif ?>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<span class="navbar-brand" href=""><?php echo " " . "$name"?>, here are the Stylist user lists.</span>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>User Lists</li>
<li><?php echo $_SESSION['sess_username'];?></li>
<li>Logout</li>
</ul>
</div>
</div>
</div>
<br> <br> <br>
<div class="container">
<?php
$mysqli = new mysqli("localhost","id7508046_root","123123123as","id7508046_isalon") or die(mysqli_error($mysqli));
$result = $mysqli->query("SELECT * FROM stylist ") or die($mysqli->error);
?>
<div class="row justify-content-center" width="80%">
<table class="table">
<thead>
<tr>
<th>UserName</th>
<th>Name</th>
<th>Image</th>
<th colspan="2">Action</th>
</tr>
</thead>
<?php
while($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo $row['username'] ?></td>
<td><?php echo $row['name'] ?></td>
// THIS PART HERE IS THE PROBLEM
<td><?php if(strcmp($row['photo'],"") == 0): {echo 'Ola';
}else:
{echo '<img src="'.$row['photo'].'">';
}
endif;
?></td>
<td>
<a href="userlist.php?edit=<?php echo $row['stylist_id']; ?>"
class="btn btn-info">Edit</a>
<a href="process.php?delete=<?php echo $row['stylist_id']; ?>"
class="btn btn-danger">Delete</a>
</td>
</tr>
<?php endwhile; ?>
</table>
</div>
<?php
function pre_r($array){
echo '<pre>';
print_r($array);
echo '</pre>';
}
?>
<br>
<br>
<div class="container justify-content-center">
<h5 class=" justify-content-center">Admin <?php echo $name;?>, create or edit an account here.</h5>
<form action="process.php" method="POST">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div class="form-group">
<label>UserName</label>
<input type="text" name="username" class="form-control" value="<?php echo $username;?>" placeholder="Enter new user Username" required>
</div>
<div class="form-group">
<label>Password</label>
<input type="text" name="password" class="form-control" value="<?php echo $password;?>" placeholder="Enter new user Password" required>
</div>
<div class="form-group">
<?php
if($update == TRUE): ?>
<button type="submit" class="btn btn-primary" name="update">Update</button>
<input type="button" class="btn btn-primary" name="reset" value="Reset" onclick="window.location.href='stylistUserlist.php'">
<?php
else: ?>
<button type="submit" class="btn btn-primary" name="save">Save</button>
<input type="button" class="btn btn-primary" name="reset" value="Reset" onclick="window.location.href='stylistUserlist.php'">
<?php
endif; ?>
</div>
</form>
</div>
</div>
</body>
Try
<td>
<?php if(!empty(trim($row['photo']))): ?>
<img src="<?php echo $row['photo'];?>"/>
<?php else: ?>
User did not upload a photo yet
<?php endif; ?>
</td>
Use below code for TD as you currently added same code in if and else both instead of using if else you can use the ternary operator.
<td>
<?php $photo = (isset($row['photo'])) ? $row['photo'] : "";
echo ($photo) ? "'. <img src=".$photo."> .'" : ""; ?>
</td>

editing php page to insert new value to my table

hey I'm Newbie and want to edit php page and adding some extra code so my problem is
I added new column to my table and I want to send data from new input text to my table to new column
I add the input text and now I wand to insert that data in new column
even I didn't find the insert query to editing it
my code is below
<?php include_once 'asset/admin-ajax.php'; ?>
<?php echo message_box('success'); ?>
<?php echo message_box('error'); ?>
<div class="row">
<div class="col-sm-12">
<div class="wrap-fpanel">
<div class="panel panel-default" data-collapsed="0">
<div class="panel-heading">
<div class="panel-title">
<strong><?php echo $this->language->form_heading()[13] ?></strong>
</div>
</div>
<div class="panel-body">
<form id="form" action="<?php echo base_url() ?>admin/employee/save_employee_award/<?php
if (!empty($award_info->employee_award_id)) {
echo $award_info->employee_award_id;
}
?>" method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="panel_controls">
<div class="form-group" id="border-none">
<label for="field-1" class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][0] ?> <span class="required">*</span></label>
<div class="col-sm-5">
<select name="designations_id" class="form-control" onchange="get_employee_by_designations_id(this.value)">
<option value="">اختر تعيين.....</option>
<?php if (!empty($all_department_info)): foreach ($all_department_info as $dept_name => $v_department_info) : ?>
<?php if (!empty($v_department_info)): ?>
<optgroup label="<?php echo $dept_name; ?>">
<?php foreach ($v_department_info as $designation) : ?>
<option value="<?php echo $designation->designations_id; ?>"
<?php
if (!empty($award_info->designations_id)) {
echo $designation->designations_id == $award_info->designations_id ? 'selected' : '';
}
?>><?php echo $designation->designations ?></option>
<?php endforeach; ?>
</optgroup>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<div class="form-group" id="border-none">
<label for="field-1" class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][1] ?> <span class="required">*</span></label>
<div class="col-sm-5">
<select name="employee_id" id="employee" class="form-control" >
<option value="">اختر موظف...</option>
<?php if (!empty($employee_info)): ?>
<?php foreach ($employee_info as $v_employee) : ?>
<option value="<?php echo $v_employee->employee_id; ?>"
<?php
if (!empty($award_info->employee_id)) {
echo $v_employee->employee_id == $award_info->employee_id ? 'selected' : '';
}
?>><?php echo $v_employee->first_name . ' ' . $v_employee->last_name ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<div class="form-group">
<label for="field-1" class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][2] ?> <span class="required">*</span></label>
<div class="col-sm-5">
<input type="text" name="award_name" class="form-control" value="<?php
if (!empty($award_info->award_name)) {
echo $award_info->award_name;
}
?>" />
</div>
</div>
<div class="form-group">
<label for="field-1" class="col-sm-3 control-label"> new column <span class="required">*</span></label>
<div class="col-sm-5">
<input type="text" name="new_column" class="form-control" value="<?php
if (!empty($award_info->new_column)) {
echo $award_info->new_column;
}
?>" />
</div>
</div>
<div class="form-group">
<label for="field-1" class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][3] ?></label>
<div class="col-sm-5">
<input type="text" name="gift_item" class="form-control" value="<?php
if (!empty($award_info->gift_item)) {
echo $award_info->gift_item;
}
?>" />
</div>
</div>
<div class="form-group">
<label for="field-1" class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][4] ?></label>
<div class="col-sm-5">
<input type="text" name="award_amount" class="form-control" value="<?php
if (!empty($award_info->award_amount)) {
echo $award_info->award_amount;
}
?>" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"><?php echo $this->language->from_body()[14][5] ?> <span class="required">*</span></label>
<div class="col-sm-5">
<div class="input-group">
<input type="text" name="award_date" placeholder="ادخل الشهر" class="form-control monthyear" value="<?php
if (!empty($award_info->award_date)) {
echo $award_info->award_date;
}
?>" data-format="dd-mm-yyyy">
<div class="input-group-addon">
<i class="entypo-calendar"></i>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-5">
<button type="submit" id="sbtn" name="sbtn" value="1" class="btn btn-primary"><?php echo $this->language->from_body()[1][12] ?></button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12" data-offset="0">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<span>
<strong><?php echo $this->language->from_body()[14][6] ?></strong>
</span>
</div>
</div>
<!-- Table -->
<table class="table table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th class="col-sm-1">رقم الموظف</th>
<th>اسم الموظف</th>
<th>اسم المكافئة</th>
<th>بند المكافئة</th>
<th>مبلغ الكافئة</th>
<th>الشهر</th>
<th> : اجراء</th>
</tr>
</thead>
<tbody>
<?php if (!empty($all_employee_award_info)):foreach ($all_employee_award_info as $v_award_info): ?>
<tr>
<td><?php echo $v_award_info->employment_id ?></td>
<td><?php echo $v_award_info->first_name . ' ' . $v_award_info->last_name; ?></td>
<td><?php echo $v_award_info->award_name;?></td>
<td><?php echo $v_award_info->gift_item; ?></td>
<td><?php echo $v_award_info->award_amount;?></td>
<td><?php echo date('F y', strtotime($v_award_info->award_date)) ?></td>
<td>
<?php echo btn_edit('admin/employee/employee_award/' . $v_award_info->employee_award_id . '/' . $v_award_info->designations_id); ?>
<?php echo btn_delete('admin/employee/delete_employee_award/' . $v_award_info->employee_award_id); ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
anyone for help please
To check the full path of the file copy paste the code at the top of the file and then you can easily go to the directory where the file is located.
<? echo base_url().'admin/employee/save_employee_award/'; exit; ?>

How to post data from sql table

Trying to work out on a Wordpress plugin which has to do with School Management stuff. Unfortunately to me the sellers do not reply or offer support which made me look a little into the code.
The thing I want to do is that, whenever a student is Absent or present or even late, the parent MUST read the reason behind it.
This is the teacher's attendence panel:
Teacher Panel
Now, whenever the parent wants to check his Child,this is what he sees:
Parent panel
As you can see, there's a Comment which was added by me hoping I could grab out the $comment also but with failure.
Adding the following snippet:
echo '<td>';
echo $comment;
echo '</td>';
didn't help at all.
The following one is the code:
<?php
$obj_mark = new Marks_Manage();
?>
<script>
$(document).ready(function() {
$('#student_list').DataTable({
responsive: true
});
} );
</script>
<!-- POP up code -->
<div class="popup-bg">
<div class="overlay-content">
<div class="result"></div>
<div class="view-parent"></div>
<div class="view-attendance"></div>
</div>
</div>
<?php if(isset($_REQUEST['attendance']) && $_REQUEST['attendance'] == 1)
{
?>
<div class="panel-body panel-white">
<ul class="nav nav-tabs panel_tabs" role="tablist">
<li class="active">
<a href="#child" role="tab" data-toggle="tab">
<i class="fa fa-align-justify"></i> <?php _e('Attendance', 'school-mgt'); ?></a>
</a>
</li>
</ul>
<div class="tab-content">
<div class="panel-body">
<form name="wcwm_report" action="" method="post">
<input type="hidden" name="attendance" value=1>
<input type="hidden" name="user_id" value=<?php echo $_REQUEST['student_id'];?>>
<div class="form-group col-md-3">
<label for="exam_id"><?php _e('Strat Date','school-mgt');?></label>
<input type="text" class="form-control" name="sdate" value="<?php if(isset($_REQUEST['sdate'])) echo $_REQUEST['sdate'];else echo date('Y-m-d');?>">
</div>
<div class="form-group col-md-3">
<label for="exam_id"><?php _e('End Date','school-mgt');?></label>
<input type="text" class="form-control" name="edate" value="<?php if(isset($_REQUEST['edate'])) echo $_REQUEST['edate'];else echo date('Y-m-d');?>">
</div>
<div class="form-group col-md-3 button-possition">
<label for="subject_id"> </label>
<input type="submit" name="view_attendance" Value="<?php _e('Go','school-mgt');?>" class="btn btn-info"/>
</div>
</form>
<div class="clearfix"></div>
<?php if(isset($_REQUEST['view_attendance']))
{
$start_date = $_REQUEST['sdate'];
$end_date = $_REQUEST['edate'];
$user_id = $_REQUEST['user_id'];
$comment = $_REQUEST['comment'];
$attendance = smgt_view_student_attendance($start_date,$end_date,$user_id,$comment);
$curremt_date =$start_date;
?>
<div class="table-responsive">
<table class="table col-md-12">
<tr>
<th width="200px"><?php _e('Date','school-mgt');?></th>
<th><?php _e('Day','school-mgt');?></th>
<th><?php _e('Attendance','school-mgt');?></th>
<th><?php _e('Comment', 'school-mgt');?></th>
</tr>
<?php
while ($end_date >= $curremt_date)
{
echo '<tr>';
echo '<td>';
echo $curremt_date;
echo '</td>';
$attendance_status = smgt_get_attendence($user_id,$curremt_date);
echo '<td>';
echo date("D", strtotime($curremt_date));
echo '</td>';
if(!empty($attendance_status))
{
echo '<td>';
echo smgt_get_attendence($user_id,$curremt_date);
echo '</td>';
}
else
{
echo '<td>';
echo __('Absent','school-mgt');
echo '</td>';
}
echo '<td>';
echo $comment;
echo '</td>';
echo '</tr>';
$curremt_date = strtotime("+1 day", strtotime($curremt_date));
$curremt_date = date("Y-m-d", $curremt_date);
}
?>
</table>
</div>
<?php }?>
</div>
</div>
</div>
<?php
}
else
{?>
<div class="panel-body panel-white">
<ul class="nav nav-tabs panel_tabs" role="tablist">
<li class="active">
<a href="#child" role="tab" data-toggle="tab">
<i class="fa fa-align-justify"></i> <?php _e('Child List', 'school-mgt'); ?></a>
</a>
</li>
</ul>
<div class="tab-content">
<div class="panel-body">
<form name="wcwm_report" action="" method="post">
<div class="table-responsive">
<table id="student_list" class="display dataTable" cellspacing="0" width="100%">
<thead>
<tr>
<th width="75px"><?php _e( 'Photo', 'school-mgt' ) ;?></th>
<th><?php echo _e( 'Child Name', 'school-mgt' ) ;?></th>
<th><?php _e('Roll No.','school-mgt');?></th>
<th> <?php echo _e( 'Class', 'school-mgt' ) ;?></th>
<th> <?php echo _e( 'Child Email', 'school-mgt' ) ;?></th>
<th><?php echo _e( 'Action', 'school-mgt' ) ;?></th>
</tr>
</thead>
<tfoot>
<tr>
<th><?php echo _e( 'Photo', 'school-mgt' ) ;?></th>
<th><?php echo _e( 'Child Name', 'school-mgt' ) ;?></th>
<th><?php _e('Roll No.','school-mgt');?></th>
<th> <?php echo _e( 'Class', 'school-mgt' ) ;?></th>
<th> <?php echo _e( 'Child Email', 'school-mgt' ) ;?></th>
<th><?php echo _e( 'Action', 'school-mgt' ) ;?></th>
</tr>
</tfoot>
<tbody>
<?php
if(!empty($school_obj->child_list))
{
foreach ($school_obj->child_list as $child_id){
$retrieved_data= get_userdata($child_id);
if($retrieved_data)
{
?>
<tr>
<td class="user_image text-center"><?php $uid=$retrieved_data->ID;
$umetadata=get_user_image($uid);
if(empty($umetadata['meta_value']))
//echo get_avatar($retrieved_data->ID,'46');
echo '<img src='.get_option( 'smgt_student_thumb' ).' height="50px" width="50px" class="img-circle" />';
else
echo '<img src='.$umetadata['meta_value'].' height="50px" width="50px" class="img-circle"/>';
?></td>
<td class="name"><?php echo $retrieved_data->display_name;?></td>
<td><?php echo get_user_meta($retrieved_data->ID, 'roll_id',true);?></td>
<td class="name"><?php $class_id=get_user_meta($retrieved_data->ID, 'class_name',true);
echo $classname= get_class_name($class_id);
?></td>
<td class="email"><?php echo $retrieved_data->user_email;?></td>
<td class="action">
<a href="?dashboard=user&page=student&action=result&student_id=<?php echo $retrieved_data->ID;?>" class="show-popup btn btn-default"
idtest="<?php echo $retrieved_data->ID; ?>"><i class="fa fa-bar-chart"></i> <?php _e('View Result','school-mgt');?></a>
<a href="?dashboard=user&page=student&tab=studentlist&action=showparent&student_id=<?php echo $retrieved_data->ID;?>" class="show-parent btn btn-default"
idtest="<?php echo $retrieved_data->ID; ?>"><i class="fa fa-user"></i><?php _e('View Parent','school-mgt');?> </a>
<a href="?dashboard=user&page=child&student_id=<?php echo $retrieved_data->ID;?>&attendance=1" class="btn btn-default"
idtest="<?php echo $retrieved_data->ID; ?>"><i class="fa fa-eye"></i> <?php _e('View Attendance','school-mgt');?> </a>
</td>
</tr>
<?php }
}
}
?>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
<?php
}
?>

Search submit button not working in CodeIgniter

I have built a page with CodeIgniter, that has a search function and a datatable.
Whenever I click the search button, the datatable will change accordingly to the parameter submitted. But it not working as I expected.
This is My Model
public function ocsmodel($biostype=null, $manufacture=null)
{
// Loading second db and running query.
if ($biostype==null and $manufacture == Null) {
$this->ocs = $this->load->database('ocsweb', TRUE);
return $this->ocs->select('ocslist.*')
->from('ocslist')
->limit(100)
->get();
}
else {
if ($manufacture == "") {
}
else {
$this->ocs = $this->load->database('ocsweb', TRUE);
return $this->ocs->select('ocslist.*')
->from('ocslist')
->where('bios_type',$biostype)
->where('smanufature',$manufacture)
->limit(100)
->get();
}
}
}
This is my controller
public function ocslist()
{
$manufactur ="";
$biostype ="";
if (isset($_POST['bios_type'])){
$biostype = $this->input->post('bios_type');
if (isset($_POST['manufacture'])){
$manufactur = $this->input->post('manufacture');
}
$data['ocs'] = $this->assetmodel->ocsmodel()->result_array();
}
else {
$data['ocs'] = $this->assetmodel->ocsmodel($biostype,$manufactur)->result_array();
}
$data['ocstype'] = $this->assetmodel->getocstype()->result_array();
$data['ocsmanu'] = $this->assetmodel->getocsmanu()->result_array();
$data['content'] = 'master/ocs_list';
$this->load->view('template', $data, FALSE);
}
And This is My View
<div class="right_col" role="main">
<div class="">
<div class="page-title">
<!--<div class="title_left">
<h3>
Master Department
<small>
List
</small>
</h3>
</div> -->
</div>
<div class="clearfix"></div>
<div class = "row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>OCS INVENTORY LIST</h2>
<ul class="nav navbar-right panel_toolbox">
<li><i class="fa fa-chevron-up"></i>
</li>
<li class="dropdown">
<i class="fa fa-wrench"></i>
</li>
<li><i class="fa fa-close"></i>
</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
<div class="x_content">
<!-- search parameters -->
<form class="form-default" method="POST" action="<? echo base_url('asset/ocslist'); ?>">
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="bios_type">Type <span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select class="select2_single form-control" tabindex="-1" name="bios_type">
<?php foreach ($ocstype as $key => $value) { ?>
<option value="<? echo $value['bios_type']?>"><? echo $value['bios_type']?></option>}
<? } ?>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="manufacture">Manufacture </label>
<div class="col-md-3">
<select class="select2_single form-control" tabindex="1" name="manufacture">
<?php foreach ($ocsmanu as $key => $value) { ?>
<option value="<? echo $value['smanufacturer']?>"><? echo $value['smanufacturer']?></option>}
<? } ?>
</select>
</div>
</div>
<div>
<button type="button" class="btn btn-info" name="submit">Search</button>
Master Asset
</div>
</div>
</form>
<table id="datatable-fixed-header" class="table responsive-utilities table-bordered">
<thead>
<tr>
<th>Type</th>
<th>Device ID</th>
<th>Manufacture</th>
<th>Model</th>
<th>Nama</th>
<<th>User ID</th>
<th>Mac_Address</th>
<th>Serial Number</th>
<th>Asset</th>
</tr>
</thead>
<tbody>
<?php foreach ($ocs as $key => $value) { ?>
<tr>
<td><?php echo $value['bios_type'];?> </td>
<td><?php echo $value['DEVICEID'];?> </td>
<td><?php echo $value['SMANUFACTURER'];?> </td>
<td><?php echo $value['smodel'];?> </td>
<td><?php echo $value['name'];?> </td>
<td><?php echo $value['userid'];?> </td>
<td><?php echo $value['macaddr'];?> </td>
<td><?php echo $value['SSN'];?> </td>
<td>Add Asset</td>
</tr>
<? } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
what about changing your controller into something like
public function ocslist()
{
$data['ocs'] = $this->assetmodel->ocsmodel($this->input->post('bios_type'), $this->input->post('manufacture'))->result_array();
$data['ocstype'] = $this->assetmodel->getocstype()->result_array();
$data['ocsmanu'] = $this->assetmodel->getocsmanu()->result_array();
$data['content'] = 'master/ocs_list';
$this->load->view('template', $data, FALSE);
}
because CI sets all POST Data to null if they doesn't exist
For more information look here
Update (20.07.2016)
according to your view try to change the button type into something like this
<button type="submit" class="btn btn-info" name="submit">Search</button>

Form issue on my website

I'm creating a form and when I save it the chosen value in the forum doesn't appear on the good page.
The goal of this form is to create a specific task for an employee, when the form is validated, the task appear on the employee tasks page.
I modified a part of the form, the "Priority" part, I added a dropdown menu instead of a text area.
Here are the codes:
Form PART.
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="taskPriority"><?php echo $priorityField; ?> <sup><?php echo $reqField; ?></sup></label>
<select name="taskPriority" class="form-control" name="taskPriority" required="" value="<?php echo isset($_POST['taskPriority']) ? $_POST['taskPriority'] : ''; ?>" />
<option value="urgent">URGENT</option>
<option value="important">IMPORTANT</option>
<option value="normal">NORMAL</option>
</select>
</div>
<div class="form-group">
<label for="taskDue"><?php echo $taskDueField; ?> <sup><?php echo $reqField; ?></sup></label>
<input type="text" class="form-control" name="taskDue" id="taskDue" required="" value="<?php echo isset($_POST['taskDue']) ? $_POST['taskDue'] : ''; ?>" />
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="addCal" value="1">
<?php echo $addToCalField; ?>
</label>
</div>
<span class="help-block"><?php echo $addToCalFieldHelp; ?></span>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="taskStatus"><?php echo $statusField; ?> <sup><?php echo $reqField; ?></sup></label>
<input type="text" class="form-control" name="taskStatus" required="" value="<?php echo isset($_POST['taskStatus']) ? $_POST['taskStatus'] : ''; ?>" />
</div>
<div class="form-group">
<label for="taskDesc"><?php echo $taskDescField; ?> <sup><?php echo $reqField; ?></sup></label>
<textarea class="form-control" required="" name="taskDesc" rows="5"><?php echo isset($_POST['taskDesc']) ? $_POST['taskDesc'] : ''; ?></textarea>
</div>
</div>
</div>
Salary Task Page PART:
<tr>
<td data-th="<?php echo $taskTitleField; ?>">
<a href="index.php?page=viewTask&taskId=<?php echo $row['empTaskId']; ?>" data-toggle="tooltip" data-placement="right" title="<?php echo $viewTaskTooltip; ?>">
<?php echo clean($row['taskTitle']); ?>
</a>
</td>
<td data-th="<?php echo $createdByField; ?>"><?php echo clean($row['postedBy']); ?></td>
<td data-th="<?php echo $priorityField; ?>"><?php echo clean($row['taskPriority']); ?></td>
<td data-th="<?php echo $statusField; ?>"><?php echo clean($row['taskStatus']); ?></td>
<td data-th="<?php echo $dateCreatedField; ?>"><?php echo $row['startDate']; ?></td>
<td data-th="<?php echo $dateDueField; ?>"><?php echo $row['dueDate']; ?></td>
<td data-th="<?php echo $actionText; ?>">
<a href="index.php?page=viewTask&taskId=<?php echo $row['empTaskId']; ?>">
<i class="fa fa-edit text-info" data-toggle="tooltip" data-placement="left" title="<?php echo $viewTaskTooltip; ?>"></i>
</a>
<a data-toggle="modal" href="#completeTask<?php echo $row['empTaskId']; ?>">
<i class="fa fa-check-square-o text-success" data-toggle="tooltip" data-placement="left" title="<?php echo $markTaskCmpTooltip; ?>"></i>
</a>
<a data-toggle="modal" href="#deleteTask<?php echo $row['empTaskId']; ?>">
<i class="fa fa-trash-o text-danger" data-toggle="tooltip" data-placement="left" title="<?php echo $deleteTaskTooltip; ?>"></i>
</a>
</td>
</tr>
The problem is that the chosen priority (Urgent, Important or Normal) doesn't appear, like on the photo.
Thank you in advance for your help.
Looks like there is more code involved. Inside the "Task Page" you refer to $row. Where is it defined. I think it's a DB result, perhaps you need to add the new property taskPriority there also.
Same for you DB structure.
It would be helpful if you can provide more information.

Categories