Im trying to build an ap in php to learn foreign languages. I got an function in it that builds a form and starts the test. it looks like:
public function test($pol_ang)
{
$words = $this->wordsArray();
if($pol_ang == 1)
{
$_SESSION['correctAnswers'] = $this->answersPolAng($words);
}else {$_SESSION['correctAnswers'] = $this->answersAngPol($words);}
if(isset($_POST['btn-confirm']))
{
$answer = strip_tags($_POST['txt_word']);
if($answer != "")
{
$_SESSION['usersAnswerArray'][$_SESSION['licznik']-1] = $answer;
$_SESSION['licznik']++;
}
if($_SESSION['licznik'] > count($words))
{
unset($_SESSION['licznik']);
$this->auth_user->redirect('result.php');
}
}
if(empty($_SESSION['licznik']))
{
$_SESSION['licznik'] = 1;
}
?>
<form method="post" class="form-signin">
<table class="table table-striped table-hover">
<thead>
<tr>
<th><?php echo $_SESSION['licznik'].' z '.count($words); ?></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<?php
$word = explode(";",$words[($_SESSION['licznik']-1)]);
if($pol_ang == 1)
{
?>
<td><?php echo $word[0]; ?></td>
<?php
}
else
{
?>
<td><?php echo $word[1]; ?></td>
<?php
}
?>
<td>-</td>
<td>
<div class="form-group">
<input type="text" class="form-control" name="txt_word" placeholder="Tłumaczenie" required />
<span id="check-e"></span>
</div>
</td>
</tr>
</tbody>
</table>
<hr />
<div class="form-group">
<button type="submit" name="btn-confirm" class="btn btn-default">
<i class="glyphicon glyphicon-log-in"></i> END
</button>
</div>
</form>
<?php
}
At the begginning wordsArray() function explode class's variable and $words becomes an array: [0]->wordLanguage1;wordLanguage2, [1]->wordLanguage1;wordLanguage2 etc...
$pol_ang is language option. If equals 1 then $_SESSION['correctAnswers'] becomes "wordsLanguage1", if equals 0 then becomes "wordLanguage2".
This function works fine. But what I wanna do is that my functio after ending the test should repeat asking for words that user entered incorrect. I can not find the solution to my problem
Related
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.
Here is the code for notification code:
<?php if(isset($notification) && $notification->result() >0 ){?>
<div class="panel-heading pull-right col-md-6"
style="height:140px; margin-top:-140px; background-color:white; overflow-y: scroll;">
<h5><strong>Student with 3 Consecutive Absences</strong></h5>
<table class="table">
<thead>
<th>Course Code-Section</th>
<th>Student Name</th>
<th>View</th>
</thead>
<tbody>
<?php foreach($notification->result() as $notif)
{
if($notif->Total >=3)
{
?>
<tr>
<td><?php echo $notif->Course_Code_Section?</td>
<td><?php echo $notif->Student?></td>
<td>
<form action="<?php echo base_url();?>index.php/attendance/check" method="post" target="_blank">
<input type="hidden" name="CID" value="<?php echo $notif->CID;?>">
<button class="btn btn-xs btn-success"><i class="icon-eye-open"></i> View</button>
<?php echo form_close();?>
</td>
</tr>
</div>
<?php }?>
<?php }?>
</tbody>
</table>
</div>
<?php }?>
Here is the notification view, the default background color is white. Therefore, I want it to make the background color red when the condition met.
Try this:
<?php
$style = '';
if(isset($notification) && $notification->result() > 0 )
{
$style = 'style="color:red"';
// Put your css style property here
}
?>
Html:
<div <?php echo $style ?>>
</div>
You can do as -
<?php
if(your condition)
{
?>
<style>
#your_div
{
background:red !important;
}
</style>
<?php
}
else
{
?>
<style>
#your_div
{
background:white !important;
}
</style>
<?php
}
?>
If your condition is true in PHP you can just this line in your tag:
<tr bgcolor="#FF0000">
I don't know if my html code will appear or not. Please refer this site:
https://www.w3schools.com/tags/att_tr_bgcolor.asp
Please try this code ,i hope this is your condition
<?php
$bcolor ='background-color:white';
if(isset($notification) && $notification->result() >0 ){
$bcolor ='background-color:white';
}?>
<div class="panel-heading pull-right col-md-6"
style="height:140px; margin-top:-140px; <?php echo $bcolor ;?> overflow-y: scroll;">
<h5><strong>Student with 3 Consecutive Absences</strong></h5>
<table class="table">
<thead>
<th>Course Code-Section</th>
<th>Student Name</th>
<th>View</th>
</thead>
<tbody>
<?php foreach($notification->result() as $notif)
{
if($notif->Total >=3)
{
?>
<tr>
<td><?php echo $notif->Course_Code_Section?</td>
<td><?php echo $notif->Student?></td>
<td>
<form action="<?php echo base_url();?>index.php/attendance/check" method="post" target="_blank">
<input type="hidden" name="CID" value="<?php echo $notif->CID;?>">
<button class="btn btn-xs btn-success"><i class="icon-eye-open"></i> View</button>
<?php echo form_close();?>
</td>
</tr>
</div>
<?php }?>
<?php }?>
</tbody>
</table>
</div>
try
<?php
$bg_red = '';
if (condition) {
$bg_red = '<style="background-color: red;">';
}
?>
<tr <php? echo $bg_red; ?>>
<td></td>
<td></td>
<td></td>
</tr>
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.
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.
I'm pretty much done with my shopping cart. I'm able to update the cart,but when I click on the delete button next to the item, it gets redirected to a blank page.
This is the top of my cart.php:
<?php
session_start();
include ("db_connection.php");//include database connection
if (isset($_SESSION['cart'])) {
if(isset($_GET['ebook_id']) && !isset($_POST['update'])){
$statement=$_SESSION['cart'];
$find=false;
$number=0;
for($i=0;$i<count($statement);$i++){
if($statement[$i]['ebook_id']==$_GET['ebook_id']){
$find=true;
$number=$i;
}
}
if($find==true){
$statement[$number]['quantity']=$statement[$number]['quantity']+1;
$_SESSION['cart']=$statement;
}else{
$ebook_title="";
$price=0;
$ebook_image="";
$query=mysqli_query($con,"SELECT * FROM ebooks WHERE ebook_id=".$_GET['ebook_id']);
while ($row=mysqli_fetch_array($query,MYSQLI_ASSOC)) {
$ebook_title=$row['ebook_title'];
$price=$row['price'];
$ebook_image=$row['ebook_image'];
}
$newData=array('ebook_id'=>$_GET['ebook_id'],
'ebook_title'=>$ebook_title,
'price'=>$price,
'ebook_image'=>$ebook_image,
'quantity'=>1);
array_push($statement, $newData);
$_SESSION['cart']=$statement;
}
}
}else{
if(isset($_GET['ebook_id'])){
$ebook_title="";
$ebook_image="";
$price=0;
$query=mysqli_query($con,"SELECT * FROM ebooks WHERE ebook_id=".$_GET['ebook_id']);
while ($row=mysqli_fetch_array($query,MYSQLI_ASSOC)) {
extract ($row);
$ebook_title=$row['ebook_title'];
$ebook_image=$row['ebook_image'];
$price=$row['price'];
}
$statement[]= array('ebook_id' => $_GET['ebook_id'],'ebook_title' => $ebook_title,'ebook_image' => $ebook_image,'price' => $price,'quantity' => 1);
$_SESSION['cart']=$statement;
}
}
?>
This is my cart form:
<form method="POST">
<table class="table">
<thead>
<tr>
<th colspan="2">E-book</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<tr>
<?php
if (isset($_POST['update'])){
$arrquantity=$_POST['quantity'];
//check validate quantity
$valid = 1;
for ($i=0; $i < count($arrquantity); $i++) {
if (!is_numeric($arrquantity[$i]) || $arrquantity[$i] < 1) {
$valid=0;
break;
}
}
if ($valid == 1){
$cart = unserialize (serialize($_SESSION['cart']));
for ($i=0;$i<count($cart);$i++) {
$cart[$i]['quantity']=$arrquantity[$i];
}
}else{
$error= "Quantity is invalid";
}
$_SESSION['cart']=$cart;
}
//delete ebook in cart
$total=0;
if (isset($_SESSION['cart'])) {
$data=$_SESSION['cart'];
$total=0;
for ($i=0;$i<count($data);$i++) {
?>
<?php echo isset($error) ? $error :'';?>
<div class="ebook">
<td><img src="<?php echo $data[$i]['ebook_image'];?>"></td>
<td><?php echo $data[$i]['ebook_title'];?></td>
<td>£<?php echo $data[$i]['price'];?></td>
<td><input type="text" value="<?php echo $data[$i]['quantity'];?>" data-price="<?php echo $data[$i]['price'];?>" data-id="<?php echo $data[$i]['ebook_id'];?>" class="quantity" name="quantity"></td>
<td class="subtotal">£<?php echo $data[$i]['price']*$data[$i]['quantity'];?></td>
<td><i class="fa fa-trash-o"></i>
</div>
</tr>
<?php
$total=($data[$i]['price']*$data[$i]['quantity'])+$total;
}
}else{
echo "<p class='text-muted'>Your shopping cart is empty</p>";
}
?>
</tbody>
<tfoot>
<tr>
<th colspan="5">Total Price</th>
<th colspan="2" id="total">£<?php echo $total; ?></th>
</tr>
</tfoot>
</table>
</div>
<!-- /.table-responsive -->
<div class="box-footer">
<div class="pull-left">
<i class="fa fa-chevron-left"></i>Continue shopping
</div>
<div class="pull-right">
<button type="submit" class="btn btn-default" name="update"><i class="fa fa-refresh"></i>Update</button>
<button type="submit" class="btn btn-primary">Checkout<i class="fa fa-chevron-right"></i>
</button>
</div>
</div>
</form>
Finally, this is the jquery to delete an item:
$(".delete").click(function(e){
e.preventDefault();
var id=$(this).attr('data-id');
$(this).parentsUntil('.ebook').remove();
$.post('./js/delete.php',{
Id:ebook_id
},function(a){
location.href="cart.php?";
});
And the delete.php page to remove the item from the cart session:
<?php
session_start();
$statement=$_SESSION['cart'];
for($i=0;$i<count($statement);$i++){
if($statement[$i]['ebook_id']!=$_POST['ebook_id']){
$newData[]=array(
'ebook_id'=>$statement[$i]['ebook_id'],
'ebook_title'=>$statement[$i]['ebook_title'],
'price'=>$statement[$i]['price'],
'ebook_image'=>$statement[$i]['ebook_image'],
'quantity'=>$statement[$i]['quantity']
);
}
}
if(isset($newData)){
$_SESSION['cart']=$newData;
}else{
unset($_SESSION['cart']);
echo '0';
}
?>
I'm new to ecommerce websites. I would really appreciate any help.
Thanks
On your delete page
<?php
if(isset($_POST['ebook_id'])){
$query=mysqli_query($con,"DELETE FROM ebooks WHERE ebook_id=".$_POST['ebook_id']);
if($query==true) {
return true;
}else {
return false;
}
}
Your JS code should be
$(".delete").click(function(e){
e.preventDefault();
var id=$(this).attr('data-id');
$.ajax({
type:"POST",
url: "delete.php",
data: {ebook_id: id},
}).done(function(data) {
$("#row_"+id+"").hide();
});
});
Your form
<form method="POST">
<table class="table">
<thead>
<tr>
<th colspan="2">E-book</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<?php
if (isset($_POST['update'])){
$arrquantity=$_POST['quantity'];
//check validate quantity
$valid = 1;
for ($i=0; $i < count($arrquantity); $i++) {
if (!is_numeric($arrquantity[$i]) || $arrquantity[$i] < 1) {
$valid=0;
break;
}
}
if ($valid == 1){
$cart = unserialize (serialize($_SESSION['cart']));
for ($i=0;$i<count($cart);$i++) {
$cart[$i]['quantity']=$arrquantity[$i];
}
}else{
$error= "Quantity is invalid";
}
$_SESSION['cart']=$cart;
}
//delete ebook in cart
$total=0;
if (isset($_SESSION['cart'])) {
$data=$_SESSION['cart'];
$total=0;
for ($i=0;$i<count($data);$i++) {
?>
<?php echo isset($error) ? $error :'';?>
//i don't know why you had open div here, so i replaced the div with tr and tr should have been inside the loop
<tr class="ebook" id="row_<?php echo $data[$i]['ebook_id'];?>">
<td><img src="<?php echo $data[$i]['ebook_image'];?>"></td>
<td><?php echo $data[$i]['ebook_title'];?></td>
<td>£<?php echo $data[$i]['price'];?></td>
<td><input type="text" value="<?php echo $data[$i]['quantity'];?>" data-price="<?php echo $data[$i]['price'];?>" data-id="<?php echo $data[$i]['ebook_id'];?>" class="quantity" name="quantity"></td>
<td class="subtotal">£<?php echo $data[$i]['price']*$data[$i]['quantity'];?></td>
<td><i class="fa fa-trash-o"></i>
</tr>
</tr>
<?php
$total=($data[$i]['price']*$data[$i]['quantity'])+$total;
}
}else{
echo "<p class='text-muted'>Your shopping cart is empty</p>";
}
?>
</tbody>
<tfoot>
<tr>
<th colspan="5">Total Price</th>
<th colspan="2" id="total">£<?php echo $total; ?></th>
</tr>
</tfoot>
</table>
</div>
<!-- /.table-responsive -->
<div class="box-footer">
<div class="pull-left">
<i class="fa fa-chevron-left"></i>Continue shopping
</div>
<div class="pull-right">
<button type="submit" class="btn btn-default" name="update"><i class="fa fa-refresh"></i>Update</button>
<button type="submit" class="btn btn-primary">Checkout<i class="fa fa-chevron-right"></i>
</button>
</div>
</div>