Only variables should be passed by reference, database/DB_active_rec.php - php

I am new to codeigniter, I just want to ask how to get rid with this thing
A PHP Error was encountered
Severity: Notice
Message: Only variables should be passed by reference
Filename: database/DB_active_rec.php
Line Number: 225
I dont know why, this suddenly comes out, but my page is doing fine, but this is at the top of my page, how to get rid of this thing, this is what i have:
Pages_Controller:
public function clients_ordered_products($id){
if(isset($_SESSION["id"])){
if($_SESSION["Usertype"]==1){
$this->load->view('admin/header');
$this->load->view('title/title_admin');
$this->load->view('admin/navigation');
$this->data["posts"] = $this->Generate_Model->getProductsClientsOrdered($id);
$this->load->view('admin/clients_ordered_products',$this->data);
$this->load->view('admin/footer');
}
else if($_SESSION["Usertype"]==0){
redirect('Pages_Controller/Ooops_Client');
}
}
else{
redirect($url);
}
}
and
Generate_Model:
public function getProductsClientsOrdered($id){
$this->db->select('*');
$this->db->select_sum('tbl_product_selected.Quantity');
$this->db->from('tbl_product_selected');
$this->db->join('tbl_product','tbl_product.Product_ID = tbl_product_selected.Product_ID');
$this->db->where('Account_ID',$id);
$this->db->where('Purchase_time',NULL);
$this->db->where('Active',1);
$this->db->group_by('tbl_product_selected.Product_ID');
$query = $this->db->get();
return $query->result();
}
and
<div id="page-wrapper">
<div class="cart">
<div class="container">
<div class="col-md-9 cart-items">
<!-- /.panel-heading -->
<div class="panel-body">
<table id="cart" class="table table-hover table-responsive">
<thead>
<tr>
<th>Product Name</th>
<th>Price</th>
<th>Quantity</th>
<th class="text-center">Subtotal</th>
<th>Action</th>
</tr>
</thead>
<?php $total = 0; ?>
<?php foreach($posts as $post){ ?>
<form action="<?php echo base_url(); ?>index.php/Transaction_Controller/removeItem/<?php echo $post->Product_selected_id; ?>" method="post">
<tbody>
<tr>
<td data-th="Product">
<div class="row">
<div class="col-sm-2 hidden-xs"> <img style="height:100px;"src="<?php echo $post->Directory?>"></div>
<div class="col-sm-10">
<h4 class="nomargin"></h4>
</div>
</div>
</td>
<td data-th="Price"><?php echo $post->Price;?></td>
<td data-th="Price" style="text-align:left"><input type="number" value="<?php echo $post->Quantity; ?>" class="form-control" style="width:60px"/></td>
<td data-th="Price" style="text-align:center"><?php echo $subtotal = $post->Price * $post->Quantity; ?></td>
<td class="actions" data-th="">
UPDATE
<button class="btn btn-danger btn-sm">DELETE<i class="fa fa-trash-o"></i></button>
</td>
</tr>
<?php $total += $subtotal; ?>
</tbody>
<tfoot>
<tr class="visible-xs">
<td class="text-center"><strong>
</strong></td>
</tr>
<tr>
<td></td>
<td colspan="2" class="hidden-xs"></td>
<td></td>
<td></td>
</tr>
</tfoot>
</form>
<?php } ?>
</table>
<center><form action="<?php echo base_url(); ?>index.php/Transaction_Controller/Products_Ordered/" method="post">
<input type="hidden" value="<?=$total?>" name="total"/>
<input type="hidden" value="<?php echo $post->Account_ID; ?>" name="id"/>
<button type="submit" class="btn btn-success btn-block">PAY NOW! <i class="fa fa-angle-right"></i></button>
</form><br/><br/>
</div>
</div>
</div>
</div>
why is this happening?

I've got the same error after upgrade from PHP 5.6 to PHP 7.1 on one project using CodeIgniter 2.
I fix it like this:
// line 224 of file /system/database/DB_active_rec.php
$explode = explode('.', $item);
return end($explode);
instead of
return end(explode('.', $item));

This notice is triggered by E_STRICT error reporting, because of this code in CodeIgniter 2:
// DB_active_rec.php line 225
end(explode('.', $item));
CodeIgniter 2 is not developed anymore and you should update to CodeIgniter 3.

Related

when i do form the popup window displays in just a second then hide again

I have popup it works normal i need to use method post to get my value from the input balise but the problem is when i do form the popup window displays in just a second then hide again and I need to click two time becausethe first time i got just the last result
<div class="List_modify">
<table class="list">
<thead class="topBar">
<tr>
<th>Prenom</th>
<th>Nom</th>
<th>CIN</th>
<th>Emails</th>
<th>Références</th>
<th>Photos</th>
<th>Niveau</th>
<th class="button_editer" style="vertical-align:middle"><span>Editer</span></th>
</tr>
</thead>
<?php $requet = "select * from Etudiants";
$resultat = mysqli_query($connecte, $requet);
while ($r = mysqli_fetch_array($resultat)) {
?>
<tbody class="container">
<tr>
<td>
<?php echo $r['Prenom']; ?>
</td>
<td>
<?php echo $r['Nom']; ?>
</td>
<td>
<?php echo $r['CIN']; ?>
</td>
<td>
<?php echo $r['Emails']; ?>
</td>
<td>
<?php echo $r['Matricule']; ?>
</td>
<td> <img src="image/<?php echo $r['Photo']; ?> " style="width: 150px; height:150px;"></td>
<td>
<?php echo $r['Niveau']; ?> </td>
<td>
<form method="POST" action="">
<input type="hidden" name="id" value="<?php echo $r['Id_Etudiant']; ?>">
<button class=" button" onclick="show()" style="vertical-align:middle" type="submit" name="submit"><span>Editer<i class=" fas fa-user-edit"></i></span>
</button>
</form>
</td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
<div class="background_page_modify" id="page_modify" onclick="hide()">
<div class="page_etudiant" onclick="event.stopPropagation()">
<div class="closebtn" id="closebtn" onclick="hide()">
<div class="circle"> +</div>
</div>
<div class="etudiant_box">
<?php
if (isset($_REQUEST['submit'])) {
$checkid = $_REQUEST['id'];
echo $checkid;
}
?>
</div>
</div>
</div>

How to insert html table row when checkbox is clicked in codeigniter

How can I solve this? I am new to this codigniter so can anyone explain to this how to solve this
<form class="form-horizontal form-label-left" method="post" action="<?php echo base_url()?>Quiz/add_assign_stu">
<input type="hidden" name="teach_id" value="<?php echo $teach_id; ?>">
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>User Id</th>
</tr>
</thead>
<tbody>
<?php
foreach ($student as $stu) {
?>
<tr>
<th>
<input class="form-group" type="checkbox" name="click[]" value="<?php echo $stu->users_id;?>">
</th>
<th><?php echo $stu->name; ?></th>
<td><?php echo $stu->users_id;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<div class="form-group">
<div class="col-md-12 col-sm-12 col-xs-12">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
controller
public function add_assign_stu()
{
$click = $this->input->post('click');
$this->Common_model->insert_record('student_exam_list',$values);
redirect("Quiz/importFile/");
}
I have a HTML table with a checkbox in one of the columns. I want to know how I could get the row data when the user clicks on the checkbox with javascript (without jquery)? Can anyone please help me with this?

Get php checkbox data from multiple tables

First I will tell what I want to achieve, and then I will explain how I was trying to do it.
I have two tables, one stores type of vessels with a description and their own Id. Then I have another table in wich the vessel type has been stored as text. My goal is to select each one (both records in both tables) with a checkbox in both and store in the table 2 the Id from the table 1.
I will introduce data, to help.
Table 1
1|Balandra|Some description
2|Bergantin|Some description
3|Whatever |Whatever.....
Table2
Balandra
Bergantin
Whatever
Then, I have created a php page that shows both tables with the checkbox I mentioned above. Checkboxes store the Table1 Id and Table2 vesseltypename.
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<a href=<?php echo '../vista/modificar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
pencil"></em></a>
<a href=<?php echo '../datos/borrar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
trash"></em></a>
</td>
<td class="hidden-xs"><?php echo
$navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid" value=<?
php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body paneltodo">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-arrow-circle-o-left"></em>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
So, I want to check both table records and store the table1 Id in the table2 idtypevessel field.
I thought that a php file could store both items and call the update function with those parameters, like this:
<?php
require './modelo.php';
$idnavio = $_GET['agruparid'];
$vessel = $_GET['agruparvessel'];
Any suggestions, because I think I have to do a button to submit this parameters, but it must be working on both tables, and I don't know how to access both foreach loop at the same time.
Thanks in advance.
E. Salas
review bellow reference code to submit multi selected checkbox values
for multi selected checkbox submission you must use [] operator after name attribute in html
index.php
<form action="/checkbox.php" method="post">
<strong>Cars:</strong><br>
<?php
$cars = array("Volvo", "BMW", "Toyota");
$colors = array("Red", "Green", "Black");
foreach($cars as $single){
?>
<input type="checkbox" name="cars[]" value="<?php echo $single; ?>">
<?php
}
<br>
<strong>colors:</strong><br>
foreach($colors as $single){
?>
<input type="checkbox" name="colors[]" value="<?php echo $single; ?>">
<?php
}
?>
<br>
<input type="submit" value="Submit!">
</form>
checkbox.php
<?php
echo "<pre>";
var_dump($_POST);
exit;
In your case:
<form action="/checkbox.php" method="post">
<div class="col-md-6">
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-pencil"></em>
<em class="fa fa-trash"></em>
</td>
<td class="hidden-xs"><?php echo $navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid[]" value=<?php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-arrow-circle-o-left"></em>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel[]" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<input type="submit" value="Submit!">
</form>
Finally I solved this with Javascript. One of my partners helped me, I post this to help people in my situation.
I created a script, here is the code:
<script type="text/javascript">
function cogeNavioDyncoopnet(){
var checkedValueNavioD = null;
var inputElements = document.getElementsByClassName('checknaviod');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValueNavioD = inputElements[i].value;
break;
}
}//return checkedValueNavioD;
var input_nav_dyn = document.getElementById("nav_dyn");
input_nav_dyn.value = checkedValueNavioD;
}
function cogeNavioForSea(){
var checkedValueNavioFs = null;
var inputElements = document.getElementsByClassName('checknaviofs');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValueNavioFs = inputElements[i].value;
break;
}
}//return checkedValueNavioFs;
var input_nav_fs = document.getElementById("nav_fs");
input_nav_fs.value = checkedValueNavioFs;
}
</script>
Then I created a Form below, that collects values and sends them to my .php control file.
<div class="hidden-xs">
<form class="hidden-xs" method="POST"
action="../datos/actualizarnavios.php">
<input id="nav_dyn" type="text" name="idnaviodyncoop">
<input id="nav_fs" type="text" name="navioforsea" >
<input id="botonasignar" type="submit" name="enviardatosdynfs">
</form>
</div>
I hope this helps. Thanks for the feedback, as always.

Retrieve data from checkboxes

I want to get all the checked data from my table. I'm using checkboxes in my table. When I click "change status", it will change my role status.
But I have problems with retrieving the checkboxes values. In the code below, it failed to update my data. Checkboxes value that I retrieve is NULL. How can I solve this problem?
Model
function deaktifRole($id_role,$editBy)
{
$data = array(
'update' =>date('Y-m-d H:i:s'),
'updateBy' =>$editBy,
'flag' => '0'
);
$this->db->where('id_role',$id_role);
$this->db->update('tbl_role',$data);
}
Controller
function deaktifRole()
{
$session_data = $this->session->userdata('logged_in');
$editBy = $session_data['username'];
foreach ($this->input->post['pilih'] as $value) {
$this->Role->deaktifRole($value->value,$editBy);
}
redirect('Home/Role');
echo '<script>alert("Your form was successfully submitted!");</script>';
}
View
<div class="x_panel">
<div class="x_title">
<h2>Manage Staff Role</small></h2>
<?php echo form_open_multipart('Home/deaktifRole');?>
<div align="right">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">Add</button>
<button type="submit" class="btn btn-primary">Change Status</button>
</div>
<div class="clearfix"></div>
</div>
<div class="x_content">
<table id="datatable-checkbox" class="table table-striped table-bordered bulk_action">
<thead>
<tr>
<th><input type="checkbox" id="check-all" class="flat"></th>
<th>No</th>
<th>Role</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php $j=0; foreach ($RoleList as $rows)
{
$j++;
?>
<tr>
<td><input type="checkbox" class="flat" name="pilih[]" value="<?php echo $rows['id_role']; ?>"></td>
<td><?php echo $j; ?></td>
<td><?php echo $rows['role']; ?></td>
<td>Aktif</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php echo form_close(); ?>
</div>
</div>
</div>
As $this->input->post('pilih') is just an associative array, you can access it directly without ->value properties. Try use this code :
foreach ($this->input->post('pilih') as $value) {
$this->Role->deaktifRole( $value,$editBy );
}
use $this->input->post('pilih');
to fetch checkbox data.

return the array of the selected id after the edit

I'm sorry but i kind of find some difficulties while editing my data , the problem is when i click the button edit, it works but when you go back to the previous page, it's like the id isn't stocked anymore so the array stays unknowns of this specific id.
Here is it's code:
<?php
include_once 'dbconfig.php';
$id = $_GET['quotauser'];
if (isset($id)) {
extract($crud->getQUOTA($id));
}
include_once 'headerQ.php';
?>
<div class="clearfix"></div>
<div class="container">
<a href="add-quota.php?add-quota" class="btn btn-large btn-info">
<i class="glyphicon glyphicon-plus"></i> Add Quota
</a>
</div>
<div class="clearfix"></div><br />
<div class="container">
<table class='table table-bordered table-responsive'>
<tr>
<th>id</th>
<th>QTANAME</th>
<th>SRVNAME</th>
<th>QTAVALUE</th>
<th colspan="3" align="center">Actions</th>
</tr>
<?php
$query = "SELECT quota.* FROM quota,user WHERE user.id=quota.id_user AND quota.id_user= '.$id.' ";
$records_per_page = 10;
$newquery = $crud->paging($query, $records_per_page);
$crud->quotaID($newquery);
?>
<tr>
<td colspan="10" align="center">
<div class="pagination-wrap">
<?php $crud->paginglink($query, $records_per_page); ?>
</div>
</td>
</tr>
</table>
</div>
<?php include_once 'footer.php'; ?>
and when the button show quota is clicked, the page that contains quota contain two options edit and delete
and the edit button takes u to this page
Edit's code is :
<?php
include_once 'dbconfig.php';
if (isset($_POST['btn-update'])) {
$id = $_GET['edit_quota'];
$QTANAME = $_POST['QTANAME'];
$SRVNAME = $_POST['SRVNAME'];
$QTAVALUE = $_POST['QTAVALUE'];
if ($crud->updateQ($id, $QTANAME, $SRVNAME, $QTAVALUE)) {
$msg = "<div class='alert alert-info'>
<strong>WOW!</strong> Quota was updated successfully <a href='UserQuota.php'>HOME</a>!
</div>";
} else {
$msg = "<div class='alert alert-warning'>
<strong>SORRY!</strong> ERROR while updating Quota !
</div>";
}
}
if (isset($_GET['edit_quota'])) {
$id = $_GET['edit_quota'];
extract($crud->getQUOTA($id));
}
?>
<?php include_once 'headerQ.php'; ?>
<div class="clearfix"></div>
<div class="container">
<?php
if (isset($msg)) {
echo $msg;
}
?>
</div>
<div class="clearfix"></div><br />
<div class="container">
<form method='post'>
<table class='table table-bordered'>
<tr>
<td>QTANAME</td>
<td><input type='text' name='QTANAME' class='form-control' value="<?php echo $QTANAME; ?>" required></td>
</tr>
<tr>
<td>SRVNAME</td>
<td><input type='text' name='SRVNAME' class='form-control' value="<?php echo $SRVNAME; ?>" required></td>
</tr>
<tr>
<td>QTAVALUE</td>
<td><input type='number' name='QTAVALUE' class='form-control' value="<?php echo $QTAVALUE; ?>" required></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-update">
<span class="glyphicon glyphicon-edit"></span> Update this Record
</button>
<i class="glyphicon glyphicon-backward"></i> CANCEL
</td>
</tr>
</table>
</form>
</div>
<?php include_once 'footer.php'; ?>

Categories