display many rows using a foreach in an array - php

Im'y trying to do something like that but it does not work.
$resDisplayFormation is a query which returns many rows, and i need to display all the rows in my table, this file is a file called by an ajax function that's why i have to do my foreach a like that
UPDATE :
<?php
include('opendb2.php');
if(isset($_POST['idSalarie'])){
$displayFormation = $bdd->prepare('SELECT * FROM FORMATION WHERE form_id_user = :idSalarie ');
$displayFormation->bindParam(':idSalarie', $_POST['idSalarie']);
$displayFormation->execute();
$resDisplayFormation=$displayFormation->fetch(PDO::FETCH_ASSOC);
$displayForm = $bdd->prepare(
'SELECT poste_nom, ups_type_contrat, serv_nom, serv_id_resp, user_credit_cpf, user_indice_salarial, form_intitule, form_organisme, form_date, form_duree,
FLOOR( DATEDIFF( CURDATE( ) , user_dateentree ) /365 ) AS dateEntree
FROM USER
INNER JOIN USER_POSTE_SERVICE
ON USER.user_id= USER_POSTE_SERVICE.ups_poste_id
INNER JOIN POSTE
ON USER_POSTE_SERVICE. ups_poste_id = POSTE.poste_id
INNER JOIN SERVICE
ON USER_POSTE_SERVICE.ups_id_serv = SERVICE.serv_id
INNER JOIN FORMATION
ON FORMATION.form_id_user = USER.user_id
WHERE user_id = :idSalarie
ORDER BY user_nom ASC');
$displayForm->bindParam(':idSalarie', $_POST['idSalarie']);
$displayForm->execute();
$resDisplayForm=$displayForm->fetch(PDO::FETCH_ASSOC);
$data = array( 'resDisplayForm'=>'');
foreach ($resDisplayForm as $key => $value) {
$data['resDisplayForm'][$key] .= $value;
}
$data['salarie'] = '
<div class="form-group">
<label for="poste_nom" class="col-sm-2 control-label">Poste occupé</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="poste_nom" readonly>
</div>
</div>
<div class="form-group">
<label for="ups_type_contrat" class="col-sm-2 control-label">Type de contrat</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="ups_type_contrat" readonly>
</div>
</div>
<div class="form-group">
<label for="serv_nom" class="col-sm-2 control-label" readonly>Service</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="serv_nom" readonly>
</div>
</div>
<div class="form-group">
<label for="serv_id_resp" class="col-sm-2 control-label" readonly>Responsable</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="serv_id_resp" readonly>
</div>
</div>
<div class="form-group">
<label for="user_credit_cpf" class="col-sm-2 control-label" readonly>Crédits CPF</label>
<div class="col-sm-2">
<input type="text" class="form-control" name="user_credit_cpf" readonly>
</div>
<label for="user_indice_salarial" class="col-sm-2 control-label" readonly>Indice Salarial</label>
<div class="col-sm-1">
<input type="text" class="form-control" name="user_indice_salarial" readonly>
</div>
<label for="dateEntree" class="col-sm-2 control-label">Ancienneté</label>
<div class="col-sm-2 input-group">
<input type="text" class="form-control" name="dateEntree" aria-describedby="basic-addon2" readonly>
<span class="input-group-addon" id="basic-addon2">années</span>
</div>
</div>';
$data['formation'] .= '
<div class="table-responsive">
<table class="table table-bordered" style="width: auto !important;">
<thead style="font-weight: bold;">’’
<tr>
<td>N</td>
<td>Intitulé</td>
<td>Organisme</td>
<td>Date</td>
<td>Durée (en heures)</td>
<td>Eval. à chaud / à froid</td>
<td>Dispositif utilisé</td>
</tr>
</thead>
<tbody class="table-striped">';
foreach ($resDisplayFormation as $ligne) {
$data['formation'] .= '
<tr>
<td>
</td>
<td>
<input type="text" class="form-control" name="form_intitule" id="form_intitule" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_organisme" id="form_organisme" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_date" id="form_date" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_duree" id="form_duree" readonly>
</td>
<td></td>
<td></td>
</tr>';
}
$data['formation'] .= '
</tbody>
</table>
</div>';
}
echo json_encode($data);die;
?>
My AJAX :
jQuery(document).ready(function($) {
$('#idSalarie').change(function(){
//on recupere la valeur de l'attribut value pour afficher tel ou tel resultat
var req=$('#idSalarie').val();
//requête ajax, appel du fichier function.php
$.ajax({
type: "POST",
url: "lib/function.php",
data: "idSalarie="+req,
dataType : "json",
//affichage de l'erreur en cas de problème
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest + '--' + textStatus + '--' + errorThrown);
},
//function s'il n'y a pas de probleme
success:function(data){
//On affiche la réponse du serveur
$('.salarie').empty();
$('.salarie').prepend(data.salarie);
$('input[name=poste_nom]').val(data.resDisplayForm.poste_nom).val();
$('input[name=ups_type_contrat]').val(data.resDisplayForm.ups_type_contrat).val();
$('input[name=serv_nom]').val(data.resDisplayForm.serv_nom).val();
$('input[name=serv_id_resp]').val(data.resDisplayForm.serv_id_resp).val();
$('input[name=user_credit_cpf]').val(data.resDisplayForm.user_credit_cpf).val();
$('input[name=dateEntree]').val(data.resDisplayForm.dateEntree).val();
$('input[name=user_indice_salarial]').val(data.resDisplayForm.user_indice_salarial).val();
$('.formation').empty();
$('.formation').prepend(data.formation)
$('input[name=form_id]').val(data.resDisplayForm.form_id).val();
$('input[name=form_intitule]').val(data.resDisplayForm.form_intitule).val();
$('input[name=form_organisme]').val(data.resDisplayForm.form_organisme).val();
$('input[name=form_date]').val(data.resDisplayForm.form_date).val();
$('input[name=form_duree]').val(data.resDisplayForm.form_duree).val();
}
});
});
});

Inside foreach instead of
$data['formation'] = '
you had to write
$data['formation'] .= '
and after foreach you also had to write
$data['formation'] .= '
This will concatenate all of you rows in correct HTML table
UPDATE
In this part of code you didn't get any value from $ligne param and dont write it in table cells. Thats why you will get 6 identical rows
foreach ($resDisplayFormation as $ligne) {
$data['formation'] .= '
<tr>
<td>
</td>
<td>
<input type="text" class="form-control" name="form_intitule" id="form_intitule" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_organisme" id="form_organisme" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_date" id="form_date" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_duree" id="form_duree" readonly>
</td>
<td></td>
<td></td>
</tr>';
}
It should be smth like this
foreach ($resDisplayFormation as $ligne) {
$data['formation'] .= '
<tr>
<td>
</td>
<td>
<input type="text" class="form-control" name="form_intitule" id="form_intitule" value='.$ligne["form_intitule"].' readonly>
</td>
<td>
<input type="text" class="form-control" name="form_organisme" id="form_organisme" value='.$ligne["form_organisme"].' readonly>
</td>
<td>
<input type="text" class="form-control" name="form_date" id="form_date" value='.$ligne["form_date"].' readonly>
</td>
<td>
<input type="text" class="form-control" name="form_duree" id="form_duree" value='.$ligne["form_duree"].' readonly>
</td>
<td></td>
<td></td>
</tr>';
}

$data['formation'] .= '
<div class="table-responsive">
<table class="table table-bordered" style="width: auto !important;">
<thead style="font-weight: bold;">’’
<tr>
<td>N</td>
<td>Intitulé</td>
<td>Organisme</td>
<td>Date</td>
<td>Durée (en heures)</td>
<td>Eval. à chaud / à froid</td>
<td>Dispositif utilisé</td>
</tr>
</thead>
<tbody class="table-striped">';
foreach ($resDisplayFormation as $ligne) {
$data['formation'] .= '
<tr>
<td>
</td>
<td>
<input type="text" class="form-control" name="form_intitule" id="form_intitule" value="'.$ligne['form_intitule'].'" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_organisme" id="form_organisme" value="'.$ligne['form_organisme'].'" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_date" id="form_date" value="'.$ligne['form_date'].'" readonly>
</td>
<td>
<input type="text" class="form-control" name="form_duree" id="form_duree" value="'.$ligne['form_duree'].'" readonly>
</td>
<td></td>
<td></td>
</tr>';
}
$data['formation'] .= '
</tbody>
</table>
</div>';
}
echo json_encode($data); die;

Related

Call to a member function hashName() on array

and I have a problem with how to enter images into the data base, in the case of the presence of input fields that increase or decrease in the case of addition or deletion
This is the code for adding data to the database
$products = $request->day_book_id;
for ($i=0; $i<count($products); $i++) {
$items = new Daybooks_units();
$items->debit= $request->debit[$i];
$items->creditor= $request->creditor[$i];
$items->data= $request->data[$i];
$items->reference= $request->reference[$i];
$items->files= $request->reference[$i];
$items->files = uploadImage('filesDayBooks',$request->images)[$i];
$items->dayBook_code= $request->dayBook_code[$i];
$items->fullAccounting_id= $request->fullAccounting_id[$i];
$items->day_book_id= $request->day_book_id[$i];
$items->branch_id= $request->branch_id[$i];
$items->save();
This is the code for the blade
<td style="padding:3px" >
<input type="text" class="search" name="search" required>
<select class="form-control search_list getData" id="search_list" name="fullAccounting_id[]"></select>
#error('fullAccounting_id')
<div class="alert alert-danger" role="alert">
{{ $message }}
</div>
#enderror
</td>
<td style="display:none" >
<input type="text" value=" " class=" form-control putParentId" name="ParentOfAccounting_manual_id[]">
</td>
<td style="display:none">
<input type="text" value=" " class=" form-control putCode" name="code_accountingManuals[]">
</td>
<td style="display:none">
<input type="text" value=" " class=" form-control debtor_creditor" name="debtor_creditor[]">
</td>
<td style="padding:3px">
<input type="text" value="0" class=" form-control totaldebit" onchange="getTotalRowPrice(this , '{{-500}}' )" name="debit[]">
#error('debit')
<div class="alert alert-danger" role="alert">
{{ $message }}
</div>
#enderror
</td>
<td style="width:100px;">
<input type="text" onchange="getTotalRowPrice(this , '{{-500}}' )" value="0" class=" form-control totalcreditor" name="creditor[]">
#error('creditor')
<div class="alert alert-danger" role="alert">
{{ $message }}
</div>
#enderror
</td>
<td style="padding:3px">
<input type="text" value="" class=" form-control" name="data[]">
</td>
<td style="width:100px;">
<select name="branch_id[]" required class="form-control">
<option></option>
#foreach($costCenters as $costCent)
<option value="{{$costCent->id}}">{{$costCent->name}}</option>
#endforeach
</select>
#error('branch_id')
<div class="alert alert-danger" role="alert">
{{ $message }}
</div>
#enderror
</td>
<td style="padding:3px">
<input type="text" class="form-control " name="reference[]" value="">
</td>
<td style="display:none;">
<input type="text" class="form-control " name="id_unit[]" value="{{ $id_unit }}">
</td>
<td style="display:none;">
<input type="text" class="form-control " name="daybooks_units[]" value="daybooks_units">
</td>
<td style="padding:3px">
<input type="file" name="images[]" multiple class="form-control" id="customFile">
</td>
<td style="padding:3px">
<input type="button" class="btn btn-success" name="add" id="add" value="add" style="color: white">
</td>
The function works smoothly if no images are inserted, but when images are uploaded, this error appears
I have no idea what your custom (not shared) uploadeImage function does, but the error SHOULD be here:
// You coded
$items->files = uploadImage('filesDayBooks',$request->images)[$i];
// It should be
$items->files = uploadImage('filesDayBooks',$request->images[$i]);
If that is not the error, please share uploadeImage code

A Database Error Occurred In codeigniter Error Number: 1048

i have problem at the time of input data to the database
this is error message
A Database Error Occurred
Error Number: 1048
Column 'username_member' cannot be null
INSERT INTO member (id_member, username_member,
password_member, nama_member, jk_member, hp_member,
alamat_member, email_member) VALUES (NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL)
Filename: C:/AppServ/www/PROJEK/system/database/DB_driver.php
Line Number: 691
my controller
function tambah()
{
$data = array(
'aksi' => site_url('member/tambah_aksi'),
'id_member' => set_value('id_member'),
'username_member' => set_value('username_member'),
'password_member' => set_value('password_member'),
'nama_member' => set_value('nama_member'),
'jk_member' => set_value('jk_member'),
'hp_member' => set_value('hp_member'),
'alamat_member' => set_value('alamat_member'),
'email_member' => set_value('email_member'),
'button' => 'DAFTAR'
);
$this->load->view('Utama/member_form', $data);
}
function tambah_aksi()
{
$data = array(
'id_member' => $this->input->post('id_member'),
'username_member' => $this->input->post('username_member'),
'password_member' => $this->input->post('password_member'),
'nama_member' => $this->input->post('nama_member'),
'jk_member' => $this->input->post('jk_member'),
'hp_member' => $this->input->post('hp_member'),
'alamat_member' => $this->input->post('alamat_member'),
'email_member' => $this->input->post('email_member')
);
$this->member_model->tambah_data($data);
redirect('Login_member');
}
View
<h3> FORM <i class="icon-arrow-left"></i> LANJUT BERBELANJA </h3> <hr class="soft"/> <table class="table table-bordered">
<tr><th> FORM DAFTAR MEMBER </th></tr>
<form action="<?php echo $aksi; ?>" method="get" class="form-horizontal" enctype="multipart/form-data">
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputUsername">Username</label>
<div class="controls">
</td>
<td>
<input type="text" name="username_member" class="form-control" placeholder="Inputkan Username" value="">
</div>
</div>
</td>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">Password</label>
<div class="controls">
</td>
<td>
<input type="password" name="password_member" placeholder="Password" value="">
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">Nama Member</label>
<div class="controls">
</td>
<td>
<input type="text" name="nama_member" placeholder="ex : Eden Hazard" value="">
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">Jenis Kelamin</label>
<div class="controls">
</td>
<td>
<input type="radio" name="jk_member" value="Laki">Pria
<br>
<input type="radio" name="jk_member" value="Wanita">Wanita
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">No Hp</label>
<div class="controls">
</td>
<td>
<input type="text" name="hp_member" placeholder="ex : 08127516331" value="">
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">Alamat Lengkap</label>
<div class="controls">
</td>
<td>
<input type="text" name="alamat_member" placeholder="ex : perum pandau blok c.19 no.16, Pekanbaru, Riau" value="">
</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="control-group">
<label class="control-label" for="inputPassword1">Email</label>
<div class="controls">
</td>
<td>
<input type="text" name="email_member" placeholder="ex : randy#yahoo.com" value="">
</div>
</div>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="id_member" value="<?php echo $id_member; ?>">
<button class="btn btn-primary" type="submit"><?php echo $button; ?></button>
</td>
</tr>
</form>
You want to change your forms method from get to post as you are processing POST data.
So your line
<form action="<?php echo $aksi; ?>" method="get" class="form-horizontal" enctype="multipart/form-data">
Change the get to post for your method.
<form action="<?php echo $aksi; ?>" method="post" class="form-horizontal" enctype="multipart/form-data">
See how that flies.

how can i show only selected checkbox productcode and price in codeIgniter

My view is like i want to show the selected textbox price and code to the controller
how can i do this
<div>
<!--second line start-->
<?php
foreach ($enq_info as $ei) {
echo form_open_multipart("Quotation/prepareQuote2/$ei->eid");
if (!empty($quote_data)) {
?>
<input name="quote_check" value="1" type="text" class="form-control">
<?php
} else {
?>
<input name="quote_check" value="no" type="text" class="form-control">
<?php
}
?>
<div class="form-group">
<div class="col-sm-2">
<label for="firstname">Enquiry Id</label>
<input name="e_id" id="e_id" value="<?php echo $ei->eid;?>" type="text" class="form-control">
</div>
<div class="col-sm-3">
<label for="lastname">Company Name</label>
<input type="text" name="company_name" id="company_name" value="<?php echo $ei->company_name;?>" class="form-control" />
</div>
<div class="col-sm-3">
<label for="lastname">Contact Person</label>
<input type="text" name="c_person" id="c_person" value="<?php echo $ei->c_person;?>" class="form-control"/>
</div>
<div class="col-sm-4">
<label>Address</label>
<textarea class="form-control" id="address" name="address" value="<?php echo $ei->address;?>"><?php echo $ei->address;?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<label for="firstname">Attn Department</label>
<textarea class="form-control" id="dept" name="dept" value="">
<?php
echo $ei->c_person." Tel ";
if(empty($ei->p_contact))
echo $ei->c_contact;
else
echo $ei->p_contact;
?>
</textarea>
</div>
<div class="col-sm-3">
<label for="lastname">Quotation For</label>
<select id="quotation_type" name="quotation_type" class="form-control m-b">
<option value="Q_Manager">Q-Manager Quote</option>
<option value="Q_Master">Q-Master Quote</option>
<option value="Q_Manager_repair">Q-Manager Repair Quote</option>
</select>
</div>
<div class="col-sm-3">
<label for="lastname">Discount</label>
<textarea class="form-control" id="discount" name="discount"></textarea>
</div>
<div class="col-sm-3">
<label for="lastname"></label><br><br>
<input type="submit" class="btn btn-success" id="default_quote" value="Generate Default Quote" onClick="rerurn disable1();"/>
</div>
</div>
<div id="showquote">
<div class="row">
<div class="hpanel">
<div class="panel-body">
<div class="col-md-12">
<table class="table table-bordered table-striped">
<tr>
<td>Product Name</td>
<td>Product Code</td>
<td>Price</td>
<td>Action</td>
</tr>
<?php
// print_r($quote_data);
foreach ($product_data as $qd) {
?>
<tr>
<td><?php echo $qd->cp_name;?></td>
<td><?php echo $qd->cp_code;?></td>
<td>
<input type="text" name="product_price[]" value="<?php echo $qd->p_price;?>">
</td>
<td>
<input type="checkbox" name="product_name[]" value="<?php echo $qd->cp_name;?>" checked/>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
<?php echo form_close(); ?>
<br><br>
<!--for new manual quote-->
<?php
}
?>
<!--third line start-->
how can i send the selected values price and also product code to the controller
just add the product code - product price with comma seperated in a hidden field like below
12-20000,13-30000,14-200 and so on
and once received in controller process it with explode or other way.
hopes you understood.

Not inserting multiple data using php mysql

I have a roles called read,write,and delete operation for a list of menu.I am listing menu with read,write,delete operation with a checkbox to insert to database but when i try to insert its not inserting multiple its inserting has one row in mysql here my code
database
Code
Form.php
<form method="post" action="insertuser.php" class="form-horizontal">
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label">Username</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="username" id="username" required>
<span class="help-block">Please Enter Username</span>
<span class="help-block" id="name_status"></span>
</div>
</div>
</fieldset>
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="password" id="password" required>
<span class="help-block">Please Enter Password</span>
</div>
</div>
</fieldset>
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label">Email Address</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="emailaddress" id="emailaddress" required>
<span class="help-block">Please Enter Email Address</span>
<span class="help-block" id="name_status1"></span>
</div>
</div>
</fieldset>
<fieldset>
<div class="form-group">
<label class="col-sm-2 control-label">Role Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="rolename" id="rolename" required>
<span class="help-block">Please Enter Role Name</span>
<span class="help-block" id="name_status2"></span>
</div>
</div>
</fieldset>
<table id="example" class="table table-striped table-bordered" >
<thead>
<th data-field="id" data-sortable="true">Menu Name</th>
<th data-field="name" data-sortable="true">Read</th>
<th data-field="actions" data-sortable="true">Edit</th>
<th data-field="actions" data-sortable="true">Delete</th>
</thead>
<tbody>
<?php
$i=0;
$selectquery=mysql_query("select * from menumanagement");
while($row=mysql_fetch_array($selectquery))
{
?>
<tr>
<td><?php echo $row["mn_menuname"]; ?></td>
<td>
<label class="checkbox checkbox-inline checked">
<span class="icons"><span class="first-icon fa fa-square-o"></span><span class="second-icon fa fa-check-square-o"></span></span><input type="checkbox" name="read1[]" id="read1" value="1_<?php echo $row["mn_id"]; ?>">
</label>
</td>
<td>
<label class="checkbox checkbox-inline checked">
<span class="icons"><span class="first-icon fa fa-square-o"></span><span class="second-icon fa fa-check-square-o"></span></span><input type="checkbox" name="edit1[]" id="edit1" value="1_<?php echo $i."_".$row["mn_id"]; ?>">
</label>
</td>
<td>
<label class="checkbox checkbox-inline checked">
<span class="icons"><span class="first-icon fa fa-square-o"></span><span class="second-icon fa fa-check-square-o"></span></span><input type="checkbox" name="delete1[]" id="delete1" value="1_<?php echo $i."_".$row["mn_id"]; ?>">
</label>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<center><button type="submit" class="btn btn-fill btn-warning btn-wd" id="addmenu">Add User</button></center>
</div>
</form>
Insert.php
<?php
include_once("includes/db.php");
if(!empty($_POST["username"]))
{
$username=$_POST["username"];
}
if(!empty($_POST["password"]))
{
$password=$_POST["password"];
}
if(!empty($_POST["emailaddress"]))
{
$emailaddress=$_POST["emailaddress"];
}
$insertquery=mysql_query("insert into useraccess(useraccess_username,useraccess_password,useraccess_emailaddress) values ('$username','$password','$emailaddress')");
$userid=mysql_insert_id();
if($insertquery)
{
if(empty($_POST["read1"]))
{
$readid=0;
}
if(empty($_POST["edit1"]))
{
$editid=0;
}
if(empty($_POST["delete1"]))
{
$deleteid=0;
}
if($_POST["read1"])
{
$readid="";
$menuid="";
$countread=count($_POST["read1"]);
for($i=0;$i<$countread;$i++)
{
$read1=$_POST["read1"][$i];
$readdiv =explode("_", $read1);
$readid .=$readdiv[0];
$menuid .=$readdiv[1];
}
}
if($_POST["edit1"])
{
$editid="";
$menuid="";
$countedit=count($_POST["edit1"]);
for($i=0;$i<$countedit;$i++)
{
$edit1=$_POST["edit1"][$i];
$editdiv=explode("_", $edit1);
$editid .=$editdiv[0];
$menuid .=$editdiv[1];
}
}
if($_POST["delete1"])
{
$deleteid="";
$menuid="";
$countdelete=count($_POST["delete1"]);
for($i=0;$i<$countdelete;$i++)
{
$delete1=$_POST["delete1"][$i];
$deletediv=explode("_", $delete1);
$deleteid .=$deletediv[0];
$menuid .=$deletediv[1];
}
}
$insertquery1=mysql_query("insert into rolemanagement(menuid,role_read,role_write,role_delete,userid) value ('$menuid','$readid','$editid','$deleteid','$userid')");
if($insertquery1)
{
header('Location: adduser.php?status="Role has been added"');
}
}
?>
Regards

Dynamic form field with jquery not post values to php

i had form that is add some fields via jquery when i click " add new " button it will update a dom , with input fields . Input fields are using a array as a name , when i click submit button , values did not post to php, only static form values are posted but not dynamically generated input values .
My fiddle is http://jsfiddle.net/4L9Rc/
It will demonstrate clearly how is my form working .
HTML
<div class="row">
<div class="col-md-12">
<form method="POST" action="http://fabtech.com/invoices/create" accept-charset="UTF-8" role="form" class="form-horizontal re-form form-inv"><input name="_token" type="hidden" value="aLngVzB1UIlY6cEedbAh55tirXGGkYJl78BL0CRN"> <legend>Invoice Details</legend>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Invoice No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter invoice no" class="form-control" name="inv_no" value=""">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Invoice date</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control date-pic" name="inv_date" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Customer</label>
<div class="col-md-7">
<select class="form-control" name="inv_customer">
<option value="">- Select Customer -</option>
<option value="suresh">suresh</option>
<option value="ABC210">ABC210</option>
<option value="QWERTy123DF">QWERTy123DF</option>
<option value="CUS002">CUS002</option>
<option value="CUS0023">CUS0023</option>
<option value="CUS003">CUS003</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PO No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control" name="po_no" value="">
</div> </div>
<div class="form-group">
<label class="col-md-4 control-label">PO date</label>
<div class="col-md-7">
<input type="text" placeholder="DD/MM/YYY" class="form-control date-pic" name="po_date" value="">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Vendor code</label>
<div class="col-md-7">
<input type="text" placeholder="Enter Vendor Code" class="form-control" name="vendor_code" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">75% abatement value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control sf" name="sf">
</div>
<div class="col-md-6 sfbox" style="display:none">
<input type="text" class="form-control sfboxval" readonly="">
</div> </div>
<div class="form-group">
<label class="col-md-4 control-label">25% Taxable Value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control tf" name="tf">
</div>
<div class="col-md-6 tfbox" style="display:none" >
<input type="text" class="form-control tfboxval" readonly="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Tax in %</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control tax" name="tax" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Grand Total</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control grandtotal" readonly="" name="grand_total">
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<legend>Particulars
<a class="btn btn-xs btn-success" id="apm"><i class="icon-plus"></i> Add new</a>
</legend>
<table id="apmr" width="69%" class="table table-striped table-bordered table-hover invoice">
<thead>
<tr>
<th width="3%">SL No</th>
<th width="25%">Description</th>
<th width="8%">Unit</th>
<th width="8%">Qty</th>
<th width="10%">Unit rate</th>
<th width="9%"> Amount</th>
</tr>
</thead>
<tbody class="roo">
<tr>
<td valign="center"> 1 </td>
<td class="tr_nt"><input type="text" name="parti[1][desc]" class="part"></td>
<td class="tr_nt"><input type="text" name="parti[1][unit]" class="part"></td>
<td class="tr_qty into"><input type="text" name="parti[1][qty]" class="part qty"></td>
<td class="tr_urate into"><input type="text" name="parti[1][urate]" class="part ur"></td>
<td class="tr_amt"><input type="text" name="parti[1][amount]" readonly="" class="part tot"></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
</td>
<td colspan="2">
Particular's Total: Rs <span class="parttotal"></span>
</td>
</tr>
</tfoot>
</table>
<p style="text-align: center;padding-top: 5px;"><input name="submit" class="btn-lg btn-primary" type="submit" value="View Invoice"></p>
</form> </div>
</div>
</div>
</div>
Javascript
//invoice particulars
var val;
$("#apm").click(function(event) {
//event.preventDefault();
//var preData = $("#apmr tr:last").html();
//console.log(preData);
//
//$("#apmr tr:last").after('<tr>' + preData + '</tr>');
var lasttd = $('.roo tr:last td:first').text();
val = parseInt(lasttd) + 1;
$(".roo tr:last").after(' <tr> <td valign="center"> ' + val + ' </td> <td class="tr_nt"><input type="text" name="parti[' + val + '][desc]" class="part"></td> <td class="tr_nt"><input type="text" name="parti[' + val + '][unit]" class="part"></td> <td class="tr_qty into"><input type="text" name="parti[' + val + '][qty]" class="part qty"></td> <td class="tr_urate into"><input type="text" name="parti[' + val + '][urate]" class="part ur"></td> <td class="tr_amt"><input type="text" name="parti[' + val + '][amount]" readonly class="part tot" ></td></tr>');
// val = val + 1;
return false;
})
var gt;
$("table.invoice").on("change", '.qty, .ur', function(event) {
calculateRow($(this).closest("tr"));
calculateTotal();
});
function calculateRow(row) {
var price = +row.find('.qty').val();
var qty = +row.find('.ur').val();
row.find('.tot').val((price * qty).toFixed(2));
}
function calculateTotal() {
var Total = 0;
$("table.invoice").find('.tot').each(function() {
Total += +$(this).val();
});
$(".parttotal").text(Total.toFixed(2));
calgrand();
}
$(".re-form").on('change', '.tax,.tf,.sf', function(event) {
calgrand();
})
function calgrand() {
var taxVal = $('.tax').val();
var parVal = $(".parttotal").text();
var result = parVal - taxVal * parVal / 100;
$('.grandtotal').val(result.toFixed(2));
if ($('.tf').is(':checked')) {
var resulttf = parVal - 25 * parVal / 100;
$('.tfboxval').val(resulttf.toFixed(2));
var result = result - resulttf;
$('.grandtotal').val(result.toFixed(2));
}
if ($('.sf').is(':checked')) {
//alert('entered');
var resultsf = parVal - 75 * parVal / 100;
$('.sfboxval').val(resultsf.toFixed(2));
var result = result - resultsf;
$('.grandtotal').val(result.toFixed(2));
}
}
$('.tf').click(function() {
$(".tfbox").toggle(this.checked);
});
$('.sf').click(function() {
$(".sfbox").toggle(this.checked);
});
in php i had
print_r($_POST['parti']);
its give out put
Array
(
[1] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
)
but i need
Array
(
[1] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
[2] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
[3] => Array
(
[desc] =>
[unit] =>
[qty] =>
[urate] =>
[amount] =>
)
....
)
javascript
Please indent your code next time. Too many changes to make in your form. At the line where you have "Enter invoice no." you have left an open quote at value=""" which is a big mistake.
Overwrite your HTML code with this:
<div class="matter">
<div class="container">
<form method="POST" action="http://fabtech.com/invoices/create" accept-charset="UTF-8" role="form" class="form-horizontal re-form form-inv">
<input name="_token" type="hidden" value="aLngVzB1UIlY6cEedbAh55tirXGGkYJl78BL0CRN">
<div class="row">
<div class="col-md-12">
<legend>Invoice Details</legend>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Invoice No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter invoice no" class="form-control" name="inv_no" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Invoice date</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control date-pic" name="inv_date" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Customer</label>
<div class="col-md-7">
<select class="form-control" name="inv_customer">
<option value="">- Select Customer -</option>
<option value="suresh">suresh</option>
<option value="ABC210">ABC210</option>
<option value="QWERTy123DF">QWERTy123DF</option>
<option value="CUS002">CUS002</option>
<option value="CUS0023">CUS0023</option>
<option value="CUS003">CUS003</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PO No</label>
<div class="col-md-7">
<input type="text" placeholder="Enter text" class="form-control" name="po_no" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PO date</label>
<div class="col-md-7">
<input type="text" placeholder="DD/MM/YYY" class="form-control date-pic" name="po_date" value="">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="col-md-4 control-label">Vendor code</label>
<div class="col-md-7">
<input type="text" placeholder="Enter Vendor Code" class="form-control" name="vendor_code" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">75% abatement value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control sf" name="sf">
</div>
<div class="col-md-6 sfbox" style="display:none">
<input type="text" class="form-control sfboxval" readonly="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">25% Taxable Value</label>
<div class="col-md-1">
<input type="checkbox" class="form-control tf" name="tf">
</div>
<div class="col-md-6 tfbox" style="display:none">
<input type="text" class="form-control tfboxval" readonly="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Tax in %</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control tax" name="tax" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Grand Total</label>
<div class="col-md-7">
<input type="text" placeholder="" class="form-control grandtotal" readonly="" name="grand_total">
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<legend>Particulars <a class="btn btn-xs btn-success" id="apm"><i class="icon-plus"></i> Add new</a>
</legend>
<table id="apmr" width="69%" class="table table-striped table-bordered table-hover invoice">
<thead>
<tr>
<th width="3%">
SL No
</th>
<th width="25%">
Description
</th>
<th width="8%">
Unit
</th>
<th width="8%">
Qty
</th>
<th width="10%">
Unit rate
</th>
<th width="9%">
Amount
</th>
</tr>
</thead>
<tbody class="roo">
<tr>
<td valign="center">
1
</td>
<td class="tr_nt">
<input type="text" name="parti[1][desc]" class="part">
</td>
<td class="tr_nt">
<input type="text" name="parti[1][unit]" class="part">
</td>
<td class="tr_qty into">
<input type="text" name="parti[1][qty]" class="part qty">
</td>
<td class="tr_urate into">
<input type="text" name="parti[1][urate]" class="part ur">
</td>
<td class="tr_amt">
<input type="text" name="parti[1][amount]" readonly="" class="part tot">
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">
</td>
<td colspan="2">
Particular's Total: Rs <span class="parttotal"></span>
</td>
</tr>
</tfoot>
</table>
<p style="text-align: center;padding-top: 5px;">
<input name="submit" class="btn-lg btn-primary" type="submit" value="View Invoice">
</p>
</div>
</div>
</form>
</div>
</div>
Your mistake was that your <form> tag was closed in the wrong place. Remember to always place tags in such a way that always the inner tags close first.

Categories