Add More rows into the existing table with PHP
Create One page for HTML using clubbed Script language here used PHP
You can use single connection file and call connection in page itself
<?php
error_reporting
(0);
define(
'DB_NAME'
,
'YOUR_DB_NAME'
);
//Your DB Name
define(
'DB_USER'
,
'root'
);
//Your DB User Name
define(
'DB_PASSWORD'
,
''
);
//Your DB Password
define(
'DB_HOST'
,
'localhost'
);
//Your Host Name
// Create connection
$db
=
new
mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Check connection
if
(
$db
->connect_error) {
die
(
"Connection failed: "
.
$db
->connect_error);
}
?>
<?php
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `inventory_detail` WHERE CONCAT(`inv_no`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `inventory_detail`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "catalog");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<!DOCTYPE html>
<html>
<body>
<form action="master.php" method="post" width="274" border="0" align="center" cellpadding="2" cellspacing="0">
<table align="center" >
<tr >
<td><input type="text" name="valueToSearch" placeholder="Value To Search"></td>
<td> <input type="submit" name="search" value="Filter"><br></td>
</tr>
</table></br>
<table border="2" align="center" cellpadding="2" cellspacing="2">
<tr>
<th width="120">INV. NO</th>
<th width="120">ITEM CODE </th>
<th>ITEM DESC.</th>
<th>SELLING PRICE </th>
<th>QUANTITY</th>
<th>TAX</th>
<th>CGST </th>
<th>SGST</th>
<th>GST </th>
</tr>
<!-- populate table from mysql database -->
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['inv_no'];?></td>
<td><?php echo $row['item_cd'];?></td>
<td><?php echo $row['item_desc'];?></td>
<td><?php echo $row['inv_date'];?></td>
<td><?php echo $row['sell_price'];?></td>
<td><?php echo $row['qty'];?></td>
<td><?php echo $row['taxable_value'];?></td>
<td><?php echo $row['cgst'];?></td>
<td><?php echo $row['sgst'];?></td>
<td><?php echo $row['gst'];?></td>
</tr>
<?php endwhile;?>
</table>
</form></br>
<table align="center" >
<tr >
<td> <input type="submit" name="search" value="Add Record"><br></td>
</tr>
</table></br>
<form action="insertmultiplerecord.php" method="get">
<table border="2px" cellspacing="0px";>
<tr>
<th width="120">INV. NO</th>
<th width="120">ITEM CODE </th>
<th>ITEM DESC.</th>
<th>SELLING PRICE </th>
<th>QUANTITY</th>
<th>INV DATE</th>
<th>TAX</th>
<th>CGST </th>
<th>SGST</th>
<th>GST </th>
</tr>
<?php
$records=2;
for($i=1;$i<=$records;$i++)
{
?>
<tr>
<td>
<input type="text" name="inv_no<?php echo $i; ?>" />
</td>
<td>
<input type="text" name="item_cd<?php echo $i;?>" />
</td>
<td>
<input type="text" name="item_desc<?php echo $i;?>" />
</td>
<td>
<input type="text" name="sell_price<?php echo $i;?>" />
</td>
<td>
<input type="text" name="qty<?php echo $i;?>" />
</td>
<td>
<input type="text" name="inv_date<?php echo $i;?>" />
</td>
<td>
<input type="text" name="taxable_value<?php echo $i; ?>" />
</td>
<td>
<input type="text" name="cgst<?php echo $i;?>" />
</td>
<td>
<input type="text" name="sgst<?php echo $i;?>" />
</td>
<td>
<input type="text" name="gst<?php echo $i;?>" />
</td>
</tr>
<?php
}
?>
</table>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------
Logic ScriptS
<?php
//http://localhost:81/Duke/insertmultiplerecord.php
include('database.php');
$size=sizeof($_GET);
echo $number=$size/10;
for($i=1;$i<=$number;$i++)
{
$index1="inv_no".$i;
$inv_no[$i]=$_GET[$index1];
$index2="item_cd".$i;
$item_cd[$i]=$_GET[$index2];
$index3="item_desc".$i;
$item_desc[$i]=$_GET[$index3];
$index4="inv_date".$i;
$inv_date[$i]=$_GET[$index4];
$index5="sell_price".$i;
$sell_price[$i]=$_GET[$index5];
$index6="qty".$i;
$qty[$i]=$_GET[$index6];
$index7="taxable_value".$i;
$taxable_value[$i]=$_GET[$index7];
$index8="cgst".$i;
$cgst[$i]=$_GET[$index8];
$index9="sgst".$i;
$sgst[$i]=$_GET[$index9];
$index10="gst".$i;
$gst[$i]=$_GET[$index10];
}
for($i=1;$i<=$number;$i++)
{
$query = "Insert into inventory_detail (inv_no,item_cd,item_desc,inv_date,sell_price,qty,taxable_value,cgst,sgst,gst)
values ('$inv_no[$i]','$item_cd[$i]','$item_desc[$i]','$inv_date[$i]','$sell_price[$i]','$qty[$i]','$taxable_value[$i]','$cgst[$i]','$sgst[$i]','$gst[$i]')";
mysqli_query($con , $query);
}
?>
Post a Comment
0Comments