Im having a form that posts an array (invoice[]) of company and invoice items.
My form got some inputs with the same name and i want to push them into the array and post them to the database as one row for each item. How can i push the items in item[0], item[1]...etc, in the same array to store it properly in the database ?
This is the input group that is been repeated in my form:
<tr>
<td class="col-xs-0">
<input type="checkbox" name="selected[]" class="checkall">
</td>
<td class="col-xs-5">
<textarea type="text" name="invoice[description]" class="form-control" id="description" rows="1" value="{{invdtl_itemDescription}}"></textarea>
</td>
<td class="col-xs-1">
<input type="number" name="invoice[unit]" class="form-control" id="unit" maxlength="5" pattern="\d+(\.\d{2})?">
</td>
<td class="col-xs-1">
<input type="number" name="invoice[qty]" class="form-control" id="qty" maxlength="5" pattern="\d+(\.\d{2})?">
</td>
<td class="col-xs-1">
<input type="number" name="invoice[price]" class="form-control" id="price" maxlength="5" pattern="\d+(\.\d{2})?">
</td>
<td class="col-xs-1">
<input type="number" name="invoice[discount]" class="form-control" id="discount" maxlength="5" pattern="\d+(\.\d{2})?">
</td>
<td class="col-xs-1">
<input type="number" name="invoice[discountPrice]" class="form-control" id="discountPrice" maxlength="5" pattern="\d+(\.\d{2})?">
</td>
<td class="col-xs-1">
<input type="number" name="invoice[total]" class="form-control" id="total" maxlength="5" pattern="\d+(\.\d{2})?">
</td>
<td class="col-xs-1">
<input type="number" name="invoice[vat]" class="form-control" id="vat" value="23" maxlength="3" pattern="\d+(\.\d{2})?">
</td>
</tr>
The array is posted with $.ajax to the database in two tables (one for invoice_header and one for invoice_details. Invoice items (the one that is been repeated in the form) should be stored in the invoice_details each row at a time.
Form data:
invoice[client]: 1
invoice[type]: receipt
invoice[invoice]: 155
invoice[date]: 2014-07-07
invoice[shipmethod]: 1
===== Item #1 =====
invoice[description]: Test
invoice[unit]: 1
invoice[qty]: 1
invoice[price]: 1
invoice[discount]: 1
invoice[discountPrice]: 1
invoice[total]: 1
invoice[vat]: 23
===== Item #2 =====
invoice[description]: Test 2
invoice[unit]: 2
invoice[qty]: 2
invoice[price]: 2
invoice[discount]: 2
invoice[discountPrice]: 2
invoice[total]: 2
invoice[vat]: 23
Related
Submit to Database Success But Value Of Debit And Kredit are 0 and 1
<table>
<tr>
<td>
<input class="form-control" name="debit[]" type="text" placeholder="Debit" autocomplete="off" required />
</td>
<td>
<input class="form-control" name="Kredit[]" type="text" placeholder="Kredit" autocomplete="off" required />
</td>
</tr>
<tr>
<th>Total</th>
<th colspan="2">
<input class="form-control" name="total" type="text" jAutoCalc="{debit[]} + {kredit[]}" />
</th>
</table>
This is the error i receive
Parsing error:unrecognied value
(Error:valueNotParsed):<*>{debit[]}+{kredit[]}
I want make option selected in dropdown html form, i am fetching data from database but into the html select cant get how to option selected
Below is the My database table data get. from that account holder is the my database value. I want to compare with select option nd make then selected into dropdown.
Array
(
[ipsf_public_pf_id] => 62
[ipsf_main_id] => 216
[account_no] => 54545455
[account_holder] => self
[pf_amt] => 1500.00
[date_of_payment] => 2020-11-15
)
and my html php form like this
$str .='<input type="hidden" name="ipsf_public_pf_id" value="<?php echo $ipsf_public_pf; ?>">
<table align="center" cellspacing="1" class="table table-bordered">
<tbody>
<tr>
<td>PPF A/c No</td>
<td>Account Holder</td>
<td>Date of Payment</td>
<td>Amount</td>
</tr>
<tr>
<td>
<input name="account_no_'.$ppf.'" type="text" id="account_no_'.$ppf.'" value="'.$account_no.'" size="20" maxlength="20" class="form-control" onkeyup="Validate_number(this)"/>
</td>
<td>
<select name="account_holder_'.$ppf.'" id="account_holder_'.$ppf.'" class="form-control">
<option value="" selected>Account Holder</option>
<option value="self">Self</option>
<option value="spouse">Spouse</option>
<option value="children">Children</option>
<!--<option value="others">Others</option>-->
</select>
</td>
<td>
<input name="date_of_payment_date_'.$ppf.'" id="date_of_payment_date_'.$ppf.'" maxlength="2" style="width: 50px;" type="text" onClick="this.value="";" value="'.$date.'" class="form-control-date" onkeyup="Validate_number(this)"/>-<input name="date_of_payment_month_'.$ppf.'" id="date_of_payment_month_'.$ppf.'" maxlength="2" style="width: 50px;" type="text" onClick="this.value="";" value="'.$month.'" class="form-control-date" onkeyup="Validate_number(this)"/>-<input name="date_of_payment_year_'.$ppf.'" id="date_of_payment_year_'.$ppf.'" maxlength="4" style="width: 65px;" type="text" onClick="this.value="";" value="'.$year.'" class="form-control-date" onkeyup="Validate_number(this)"/>
</td>
<td>
<input name="ppf_amt_'.$ppf.'" type="text" id="ppf_amt_'.$ppf.'" value="'.$pf_amt.'" size="10" onBlur="javascript:increment_ppf_amnt(this.value, '.$ppf.');" maxlength="14" class="form-control-date" onkeyup="Validate_number(this)"/>
<input type="hidden" name="prev_ppf_amount_'.$ppf.'" id="prev_ppf_amount_'.$ppf.'" value="'.$ppf.'"/>
<input type="hidden" name="is_added_0" id="is_added_0" value="no"/>
</td>
</tr>
</tbody>
<input type="hidden" name="total_ppf_amount" id="total_ppf_amount" value="0"/>
</table>';
I am confused how to selected that option inside .
Anyone know then please help me
On your html just fill the selected="<?=$selectedOption;?>.
Basically the logic behind it is: you fetch the data that you want to, and the values thaty ou on option tags you will gonna use the selected id / value or whatever that you want to use for in the selected atrribute on the <select></<select> html tag.
I have a table with six rows and i have assigned same names to the values to each row , how can i save the six row values into to the database using php in codeigniter
<td>
<input type="text" name="compscheme" id="compscheme" class="form-control m-b-10">
</td>
<td>
<input type="text" name="compbrands" id="compbrands" class="form-control m-b-10">
</td>
<td>
<input type="text" name="companyname" id="companyname" class="form-control m-b-10">
</td>
<td>
<input type="text" name="cmpyscheme" id="cmpyscheme" class="form-control m-b-10">
</td>
</tr>
<tr>
<td>
<input type="text" name="compscheme" id="compscheme" class="form-control m-b-10">
</td>
<td>
<input type="text" name="compbrands" id="compbrands" class="form-control m-b-10">
</td>
<td>
<input type="text" name="companyname" id="companyname" class="form-control m-b-10">
</td>
<td>
<input type="text" name="cmpyscheme" id="cmpyscheme" class="form-control m-b-10">
</td>
in this way i have six rows. should i use multiple array tag or any other way for inserting
you should use array input name like- companyname[] -
<!--
<td>
<input type="text" name="compscheme[]" id="compscheme" class="form-control m-b-10">
</td>
<td>
<input type="text" name="compbrands[]" id="compbrands" class="form-control m-b-10">
</td>
.......
.......
.......
-->
<?php
if(($this->input->server('REQUEST_METHOD')=='POST')){
for ($i=0; $i <count($_POST['cmpyscheme']); $i++) {
$data=array(
'table_column_name'=>$_POST['cmpyscheme'][$i],
);
// for 6 rows
if($i==5){
echo $_POST['cmpyscheme'][$i];
}
}
}
?>
You can get directly value of six row.
$cmpyscheme=$_POST['cmpyscheme'][5];
$compbrands=$_POST['compbrands'][5];
$companyname=$_POST['companyname'][5];
$cmpyscheme=$_POST['cmpyscheme'][5];
I want to received 4,5 row data in php. When I put values in the form like 3 or 4 row than I want to received the same data in php :(
I am trying to make a pos. When the customer order multiple product than the order row automatically increase but there is no limit 5, 10, 15 or else.
And I want to received the data value in same rows like
<form name="data" method="post" action="data_rec.php" enctype="multipart/form-data">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
</tr>
<tr>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
</tr>
<tr>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
</tr>
<tr>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
</tr>
<tr>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
<td>
<input name="data[]" type="text" id="data1" />
</td>
</tr>
</table>
<input name="Submit" type="submit" value="SEND">
</form>
<?php
foreach (array_combine($_POST['data'], $_POST['data']) as $i => $data) {
$i."<br />";
echo $data."<br />";
echo "SAGOR"."<br />";
}
?>
Output :
1
SAGOR
2
SAGOR
3
SAGOR
4
SAGOR
5
SAGOR
6
SAGOR
7
SAGOR
8
SAGOR
SAGOR
But I need :
1 2 3 4
SAGOR
5 6 7 8
You can add rows to your form on the browser with JS or JQuery.
You must give each row's elements unique ids/names like: <input name="data2" type="text" id="data2" /> <input name="data3" type="text" id="data3" />...
You will receive them all in you $_POST when the user submit the form
This is my table. I am developing billing application in core php mysql. Each row insert into table means need more memory, so I need to insert an one customer bill in a single row with all values separated by comma,
<table id="options-table" border="1">
<tbody><tr>
<th>S.NO</th>
<th>Product Name</th>
<th>Qty</th>
<th>Rate ($)</th>
<th>Total ($)</th>
<th>Option</th>
</tr>
<tr>
<td><span id="snum">1.</span></td>
<td><input type="text" name="productname[]" required="" class="ui-wizard-content valid"></td>
<!--<td><input type="text" style="width:80px;" name="itemcode" /></td> -->
<td><input type="text" class="qty ui-wizard-content valid" name="qty[]" required=""></td>
<td><input type="text" class="rate ui-wizard-content valid" name="rate[]" required=""></td>
<td><input type="text" class="tcost ui-wizard-content valid" name="tcost[]" readonly=""></td>
<td><input type="button" class="del btn-danger ui-wizard-content" value="Delete"></td>
</tr>
<tr>
<td><span id="snum">2.</span></td>
<td><input type="text" name="productname[]" required="" class="ui-wizard-content valid"></td>
<!--<td><input type="text" style="width:80px;" name="itemcode" /></td> -->
<td><input type="text" class="qty ui-wizard-content valid" name="qty[]" required=""></td>
<td><input type="text" class="rate ui-wizard-content valid" name="rate[]" required=""></td>
<td><input type="text" class="tcost ui-wizard-content" name="tcost[]" readonly=""></td>
<td><input type="button" class="del btn-danger" value="Delete"></td>
</tr><tr><td><span id="snum3">3.</span></td><td><input type="text" name="productname[]" required="" class="valid"></td> <td><input type="text" class="qty valid" name="qty[]" required=""></td> <td><input type="text" class="rate valid" name="rate[]" required=""></td> <td><input type="text" class="tcost" name="tcost[]" readonly=""></td><td><input type="button" class="del btn-danger" value="Delete"></td></tr><tr><td><span id="snum3">4.</span></td><td><input type="text" name="productname[]" required="" class="valid"></td> <td><input type="text" class="qty valid" name="qty[]" required=""></td> <td><input type="text" class="rate valid" name="rate[]" required=""></td> <td><input type="text" class="tcost" name="tcost[]" readonly=""></td><td><input type="button" class="del btn-danger" value="Delete"></td></tr><tr><td><span id="snum3">6.</span></td><td><input type="text" name="productname[]" required="" class="valid"></td> <td><input type="text" class="qty valid" name="qty[]" required=""></td> <td><input type="text" class="rate valid" name="rate[]" required=""></td> <td><input type="text" class="tcost valid" name="tcost[]" readonly=""></td><td><input type="button" class="add btn-success" value="Add More"></td></tr>
</tbody></table>
In the above table array values are insert into single row, PRODUCT NAME are separated with comma(,) same as QTY, RATE and TOTAL, can you suggest me.
Table structure:
S.NO Product Name Qty Rate ($) Total ($)
1. flowers 5 5 35
2. jasmine 6 5 30
3. rose 10 8 80
4. marigold 15 9 135
6.
This is example one , i tried this code work fine.
<?php
include 'connection/db_connection.php';
if(isset($_REQUEST['save'])) {
$product_name = implode(",", $_REQUEST["product"]);
print $product_name;
}
$query="insert into product (product_name) values('".$product_name."')";
$sql=mysql_query($query);
if($sql)
echo "success";
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form name="myform" method="post">
<input type="text" name="product[]" value="rose">
<input type="text" name="product[]" value="garlands">
<input type="text" name="product[]" value="marigold">
<input type="text" name="product[]" value="jasmine">
<input type="text" name="product[]" value="jasmine garlands">
<input type="submit" name="save" value="Save">
</form>
</body>
</html>