I am trying to generate bill for the customer.When I add items in the form and click on add button I want it to create table and show the bill. But its not working fine. I tried to use sql query but it is showing only 2 items and sometimes blank. when there are 3 4 items inserted into database. Please any one can clear me where am going wrong.
<tr>
<td height="517"><form name="form1" method="post" action="">
<table width="400" border="0" align="center" cellpadding="10" cellspacing="0">
<tr>
<td colspan="2"><div align="center">Add item Details </div></td>
</tr>
<tr>
<td width="117">Item Name</td>
<td width="243"><input name="itemName" type="text" id="itemName">
</td>
</tr>
<tr>
<td>Quantity</td>
<td><input name="qty" type="text" id="qty"></td>
</tr>
<tr>
<td>Price </td>
<td><input name="price" type="text" id="price"></td>
</tr>
<tr>
<td>Vat </td>
<td><input name="vat" type="text" id="vat"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Add"></td>
</tr>
</table>
</form>
<p align="center">Bill Record</p>
<p align="center"> </p>
<table width="70%" border="0" align="center" cellpadding="10" cellspacing="0">
<tr>
<th>Item Name</th>
<th>Quantity</th>
<th>Price</div></th>
<th>Vat</th>
<th>total</th>
</tr>
<% double grandTotal=0;
try
{
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from bill where cname='"+session.getAttribute("cname")+"' order by datetime asc");
while(rs.next())
{
%>
<tr>
<td><%=rs.getString("itemName")%></td>
<td><%=rs.getString("qty")%></td>
<td><%=rs.getString("price")%></td>
<td><%=rs.getString("vat")%></td>
<td><%= rs.getString("total") %></td>
<% grandTotal+=Double.parseDouble( rs.getString("total"));%>
</tr>
<%
} %>
<tr>
<td></td>
<td></td>
<td></td>
<td>grandTotal</td>
<td><%= grandTotal %> </td>
</tr>
<% con.close();
}
catch(Exception e)
{
out.println("Error: "+e);
}
%>
</table>
</tr>
And here is the code where I am adding values into database.
<%
if(request.getMethod().equals("POST"))
{
String itemName="";
int qty;
double price,vat,total;
grandTotal=0;
boolean exists=false;
itemName=request.getParameter("itemName");
qty=Integer.parseInt(request.getParameter("qty"));
price=Double.parseDouble(request.getParameter("price"));
vat=Double.parseDouble(request.getParameter("vat"));
total=price+vat;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
try
{
Statement st=con.createStatement();
st.executeUpdate("INSERT into bill values('"+session.getAttribute("cname")+"','" + dateFormat.format(date) + "','"+itemName+"','"+qty+"','"+price+"','"+vat+"','"+total+"','"+grandTotal+"')");
out.println("<script> alert('Item Added Successfully')</script>");
}
Related
I have an onclick function in my HTML: <td onclick showDep(this, <?= $id;?>) >
I would like to change the background of the relative table row that has a specific ID, e.g. clicking on first row function I want to go to the row that has id="4".
function showDep(t, id) {
$(t).closest('tr').each(function() {
$.find('.rowDep').attr('id' = id).css({
'background': 'gray'
})
})
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<tr>
<td onclick="showDep(this, $<?= $id;?>)"><b>Movements</b> </td>
</tr>
<tr class=" rowDep " id="26 ">
<td>Landing</td>
</tr>
<tr class="rowDep " id="8 ">
<td><input type="time " class="landing " value="<?=$v[ 'landing'];?>"></td>
</tr>
<tr>
<td>Block</td>
</tr>
<tr class="rowDep" id="4">
<td><input type="time" class="block" value="<?=$v['block'];?>"></td>
</tr>
<tr>
<td><button onclick="sendMVT(this, <?=$id;?>)" class="inpBtnSave" type="button">MVT</button> </td>
</tr>
My table has 2 rows with 3 columns, followed by a submit button. I would like the submit button to be in the center of the first 2 columns, but instead it is in the center of the 3 columns. How can I center it within the first 2 column?
<table>
<tr>
<td align="right">Label 1:</td>
<td align="left"><input type="text" name="input1"></td>
<td> a link</td>
</tr>
<tr>
<td align="right">Label 2:</td>
<td align="left"><input type="text" name="input2"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit"></td>
</tr>
</table>
As mentioned in the comments, you'll need three columns in your last row, merging the first two with colspan. Also, don't use the deprecated align attribute.
.center {
text-align: center;
}
<table>
<tr>
<td align="right">Label 1:</td>
<td align="left"><input type="text" name="input1"></td>
<td> a link</td>
</tr>
<tr>
<td align="right">Label 2:</td>
<td align="left"><input type="text" name="input2"></td>
</tr>
<tr>
<td colspan="2" class="center"><input type="submit" name="submit"></td>
<td> </td>
</tr>
</table>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Below is my html code consists of a table with two rows and the second row consists of two tables in each td. now the second table in the second td displays in middle but not in top. I want that table in top
<table>
<tr>
<th>Upload a File to BlockChain</th>
<th>Transaction Details</th>
</tr>
<tr>
<td>
<table style="width: 100%" bgcolor="#cceeff">
<tr>
<td>Name <br> <input type=text name=textnames
placeholder="Employee Name" id="textname" size="60">
</td>
</tr>
<tr>
<td>Employee Id <br> <input type="text"
placeholder="Employee Id" name="fathername" id="fathername"
size="60"></td>
</tr>
<tr>
<td>Contact No. <br> <input type="text" name="paddress"
placeholder="Contact Number" id="paddress" size="60"></td>
</tr>
</table>
</td>
<td>
<table width="100" height="100">
<tr>
<th>From Party</th>
<th>To Party</th>
<th>Docs</th>
<th>Created State</th>
<th>Status</th>
</tr>
</table>
</td>
</tr>
</table>
See this fiddle
i've changed your html as below
<div>
<table style="width: 50%; float:left">
<tr>
<th>Upload a File to BlockChain</th>
</tr>
<tr>
<td>
<table style="width: 100%;" bgcolor="#cceeff">
<tr>
<td>Name
<br>
<input type=text name=textnames placeholder="Employee Name" id="textname">
</td>
</tr>
<tr>
<td>Employee Id
<br>
<input type="text" placeholder="Employee Id" name="fathername" id="fathername">
</td>
</tr>
<tr>
<td>Contact No.
<br>
<input type="text" name="paddress" placeholder="Contact Number" id="paddress">
</td>
</tr>
</table>
</td>
</tr>
</table>
<table style="width: 50%; float:left">
<tr>
<th colspan="5">Transaction Details</th>
</tr>
<tr>
<th>From Party</th>
<th>To Party</th>
<th>Docs</th>
<th>Created State</th>
<th>Status</th>
</tr>
</table>
</div>
You can remove the height="100" and add valign="top" to the td.
<td valign="top">
<table width="100">
<tr>
<th>From Party</th>
<th>To Party</th>
<th>Docs</th>
<th>Created State</th>
<th>Status</th>
</tr>
</table>
</td>
How to store a html table data into MySQL database.
Sample Html code is given below. In original, there is about thousand form on the same page.
<thead>
<tr>
<th> Id</th>
<th>From area</th>
<th>To area</th>
<th>Basic price</th>
</tr>
</thead>
<form action="basicprice.php" method="get" name="basicprice">
<tr>
<td>4</td>
<td class="static">Address 1</td>
<td class="static">Airport 1</td>
<td class="center"><input type="text" name="basicprice" value="54"></td>
<td><input name="submit" type="submit" value="Save"></td>
</tr>
</form>
<form action="basicprice.php" method="get" name="basicprice">
<tr>
<td>4</td>
<td class="static">Address 1</td>
<td class="static">Airport 1</td>
<td class="center"><input type="text" name="basicprice" value="54"></td>
<td><input name="" type="submit" value="Save"></td>
</tr>
I want create a database from these details. Need Help.
Thanks in advance
Use only one form and add input feild name as array[]
<form action="basicprice.php" method="get" name="basicprice">
<tr>
<td>4</td>
<td class="static">Address 1</td>
<td class="static">Airport 1</td>
<td class="center"><input type="text" name="basicprice[]" ></td>
<td><input name="submit" type="submit" value="Save"></td>
</tr>
</form>
In this array you will get all values no need to write forms again and again.
Have a look on bellow link
"PHP - Insert data from HTML table into MySQL database" might give you some idea on how to make insert query using array elements
How will I properly display data from database to textbox when the button "search" is clicked? It should display the item name and the price of that product code
enter image description here
Controller
public ActionResult Index(string searchString)
{
using(MyDatabaseEntities db = new MyDatabaseEntities())
{
var products = from s in db.Products
select s;
if (!String.IsNullOrEmpty(searchString))
{
products = products.Where(s => s.ProductCode.Equals(searchString));
}
return View(products.ToList());
}
}
Index
<div class="form-group">
<table style="text-align:left; margin-bottom:10px;">
<tr>
<td>Item Code</td>
<td>#Html.TextBox("SearchString")
</td>
<tr style="background-color:lightgray;">
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" class="btn btn-block btn-info"id="buttonsearch" value="Search" />
</td>
</tr>
<tr>
<td> </td>
</tr>
#foreach (var item in Model) {
<tr>
<td style="text-align:left;">Item Name</td
<td>#Html.DisplayFor(modelItem=> item.ProductName)</td>
</tr>
<tr>
<td>Unit Price</td>
<td style="text-align:right;">#Html.DisplayFor(modelItem => item.Price)</td>
</tr>
}
<tr>
<td style="text-align:left;">Quantity</td>
<td>
<input type="text" id="quantity" class="input-sm" />
<span class="error">Product Name required</span>
</td>
</tr>
<tr>
<td style="text-align:left;">Discount</td>
<td>
<input type="text" id="discount" class="input-sm" style="text-align:right;" placeholder="0.00" />
<span class="error">Product Name required</span>
</td>
</tr>
</table>
</div>
Instead of .ToList() use .FirstOrDefault(); just in case you want to populate one record in your textbox.