Php 选中时将数据从表中获取到另一个表
这个程序工作正常,我只是不知道如何使这个额外的功能工作 dbconfig.phpPhp 选中时将数据从表中获取到另一个表,php,sql,Php,Sql,这个程序工作正常,我只是不知道如何使这个额外的功能工作 dbconfig.php <?php $db_host = "localhost"; $db_name = "testproduct"; $db_user = "root"; $db_pass = ""; try{ $db_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass); $db_con
<?php
$db_host = "localhost";
$db_name = "testproduct";
$db_user = "root";
$db_pass = "";
try{
$db_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
$db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e){
echo $e->getMessage();
}
?>
产品管理
在产品管理中,我将添加产品信息名称、价格、库存等
add_form.php
<?php
require_once 'dbconfig.php';
if($_POST)
{
$fname = $_POST['name'];
$lname = $_POST['actualprice'];
$contactnum = $_POST['sellprice'];
$email = $_POST['Stock'];
try{
$stmt = $db_con->prepare("INSERT INTO tblproduct(name,actualprice,sellprice,Stock) VALUES(:pname,:pactualprice,:psellprice,:pStock)");
$stmt->bindParam(":pname", $name);
$stmt->bindParam(":pactualprice", $actualprice);
$stmt->bindParam(":psellprice", $sellprice);
$stmt->bindParam(":pStock", $Stock);
if($stmt->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
<style type="text/css">
#dis{
display:none;
}
</style>
<div id="dis">
</div>
<form method='post' id='emp-SaveForm' action="#">
<table class='table table-bordered'>
<tr>
<td>Product Name</td>
<td><input type='text' name='name' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td>Actual Price</td>
<td><input type='text' name='actualprice' class='form-control' placeholder='EX : Web Design, App Design' required></td>
</tr>
<tr>
<td>Sell Price</td>
<td><input type='text' name='sellprice' class='form-control' placeholder='EX : 180000' required></td>
</tr>
<tr>
<td>Stock</td>
<td><input type='text' name='Stock' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
</form>
<?php
require_once 'dbconfig.php';
if($_POST)
{
$pname = $_POST['pname'];
$gname = $_POST['gname'];
$saledate = $_POST['saledate'];
$quantity = $_POST['quantity'];
$actualprice = $_POST['actualprice'];
$sellprice = $_POST['sellprice'];
$profit = $_POST['profit'];
$carryO = $_POST['carryO'];
$sells = $_POST['sells'];
$expense = $_POST['expense'];
try{
$stmt = $db_con->prepare("INSERT INTO tblsales(pname,gname,saledate,quantity,actualprice,sellprice,carryO,sells,expense,profit)
VALUES(:upname,:ugname,:usaledate,:uquantity,:uactualprice,:usellprice,:ucarryO,:usells,:uexpense,:uprofit)");
$stmt->bindParam(":upname", $pname);
$stmt->bindParam(":ugname", $gname);
$stmt->bindParam(":usaledate", $saledate);
$stmt->bindParam(":uquantity", $quantity);
$stmt->bindParam(":uactualprice", $actualprice);
$stmt->bindParam(":usellprice", $sellprice);
$stmt->bindParam(":ucarryO", $carryO);
$stmt->bindParam(":usells", $sells);
$stmt->bindParam(":uexpense", $expense);
$stmt->bindParam(":uprofit", $profit);
if($stmt->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
<div id="dis">
</div>
<form method='post' id='emp-SaveForm' action="#">
<table class='table table-bordered'>
<tr>
<td>Product Name</td>
<td><input type='text'name='pname' class='form-control' required> </td>
</tr>
<tr>
<td>Guest Name</td>
<td><input type='text' name='gname' class='form-control' required> </td>
</tr>
<tr>
<td>Sale Date</td>
<td><input type='date' name='saledate' class='form-control' required></td>
</tr>
<tr>
<td>Quantity</td>
<td><input type='text' name='quantity' class='form-control' id="quantity" required></td>
</tr>
<tr>
<td>Actual Price</td>
<td>
<input type='text'name ="actualprice" id="aaprice" class='form-control' required></td>
</tr>
<tr>
<td>Selling Price</td>
<td>
<input type='text' name='sellprice' class='form-control' type = "number" id="ssprice" required></td>
</tr>
<tr>
<td>Carry Over</td>
<td><input type='text' name='carryO' class='form-control' required></td>
</tr>
<tr>
<td>Sells</td>
<td><input type='text' name='sells' class='form-control' required></td>
</tr>
<tr>
<td>Expense</td>
<td><input type='text' name='expense' class='form-control' required></td>
</tr>
<tr>
<td>Profit</td>
<td><input name='profit' class='form-control' type = "number" id="profit" required></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
#dis{
显示:无;
}
品名
实际价格
售价
股票
保存此记录
index.php
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Product Name</th>
<th>Actual Price</th>
<th>Sell Price</th>
<th>Stock</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
$stmt = $db_con->prepare("SELECT * FROM tblproduct ORDER BY id DESC");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['actualprice']; ?></td>
<td><?php echo $row['sellprice']; ?></td>
<td><?php echo $row['Stock']; ?></td>
<td align="center">
<a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Product Name</th> //selected from product management table
<th>Sale Date</th>//(user input)
<th>Quantity</th>//(user input)
<th>Actual Price</th> //price of the selected product on the management table
<th>Selling Price</th> //price of the selected product on the management table
<th>Carry Over</th> //stock from the selected product on the management table
<th>Sells</th>//selling price of the selected product on the management table * quantity(user input)
<th>Expense</th>
<th>Profit</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
if(isset($_POST['months'])){ $months = $_POST['months']; }else { $months='';}
$stmt = $db_con->prepare("SELECT * FROM tblsales WHERE MONTH(saledate) = '".$months."' ");
//this is for the sales management for the monthly view function didn't include the my months select this post already long enough
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['pname']; ?></td>
<td><?php echo $row['saledate']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['actualprice']; ?></td>
<td><?php echo $row['sellprice']; ?></td>
<td><?php echo $row['carryO']?></td>
<td><?php echo $row['sells']?></td>
<td><?php echo $row['expense']?></td>
<td><?php echo $row['profit']; ?></td>
<td align="center">
<a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
品名
实际价格
售价
股票
编辑
删除
销售管理
这里是销售中的问题,我将添加一个需要产品名称的销售记录。该产品将从产品管理表中选择,包括该特定产品的其他信息(实际价格、库存、销售价格),这些信息将显示在索引上
add_form.php
<?php
require_once 'dbconfig.php';
if($_POST)
{
$fname = $_POST['name'];
$lname = $_POST['actualprice'];
$contactnum = $_POST['sellprice'];
$email = $_POST['Stock'];
try{
$stmt = $db_con->prepare("INSERT INTO tblproduct(name,actualprice,sellprice,Stock) VALUES(:pname,:pactualprice,:psellprice,:pStock)");
$stmt->bindParam(":pname", $name);
$stmt->bindParam(":pactualprice", $actualprice);
$stmt->bindParam(":psellprice", $sellprice);
$stmt->bindParam(":pStock", $Stock);
if($stmt->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
<style type="text/css">
#dis{
display:none;
}
</style>
<div id="dis">
</div>
<form method='post' id='emp-SaveForm' action="#">
<table class='table table-bordered'>
<tr>
<td>Product Name</td>
<td><input type='text' name='name' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td>Actual Price</td>
<td><input type='text' name='actualprice' class='form-control' placeholder='EX : Web Design, App Design' required></td>
</tr>
<tr>
<td>Sell Price</td>
<td><input type='text' name='sellprice' class='form-control' placeholder='EX : 180000' required></td>
</tr>
<tr>
<td>Stock</td>
<td><input type='text' name='Stock' class='form-control' placeholder='EX : john doe' required /></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
</form>
<?php
require_once 'dbconfig.php';
if($_POST)
{
$pname = $_POST['pname'];
$gname = $_POST['gname'];
$saledate = $_POST['saledate'];
$quantity = $_POST['quantity'];
$actualprice = $_POST['actualprice'];
$sellprice = $_POST['sellprice'];
$profit = $_POST['profit'];
$carryO = $_POST['carryO'];
$sells = $_POST['sells'];
$expense = $_POST['expense'];
try{
$stmt = $db_con->prepare("INSERT INTO tblsales(pname,gname,saledate,quantity,actualprice,sellprice,carryO,sells,expense,profit)
VALUES(:upname,:ugname,:usaledate,:uquantity,:uactualprice,:usellprice,:ucarryO,:usells,:uexpense,:uprofit)");
$stmt->bindParam(":upname", $pname);
$stmt->bindParam(":ugname", $gname);
$stmt->bindParam(":usaledate", $saledate);
$stmt->bindParam(":uquantity", $quantity);
$stmt->bindParam(":uactualprice", $actualprice);
$stmt->bindParam(":usellprice", $sellprice);
$stmt->bindParam(":ucarryO", $carryO);
$stmt->bindParam(":usells", $sells);
$stmt->bindParam(":uexpense", $expense);
$stmt->bindParam(":uprofit", $profit);
if($stmt->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
<div id="dis">
</div>
<form method='post' id='emp-SaveForm' action="#">
<table class='table table-bordered'>
<tr>
<td>Product Name</td>
<td><input type='text'name='pname' class='form-control' required> </td>
</tr>
<tr>
<td>Guest Name</td>
<td><input type='text' name='gname' class='form-control' required> </td>
</tr>
<tr>
<td>Sale Date</td>
<td><input type='date' name='saledate' class='form-control' required></td>
</tr>
<tr>
<td>Quantity</td>
<td><input type='text' name='quantity' class='form-control' id="quantity" required></td>
</tr>
<tr>
<td>Actual Price</td>
<td>
<input type='text'name ="actualprice" id="aaprice" class='form-control' required></td>
</tr>
<tr>
<td>Selling Price</td>
<td>
<input type='text' name='sellprice' class='form-control' type = "number" id="ssprice" required></td>
</tr>
<tr>
<td>Carry Over</td>
<td><input type='text' name='carryO' class='form-control' required></td>
</tr>
<tr>
<td>Sells</td>
<td><input type='text' name='sells' class='form-control' required></td>
</tr>
<tr>
<td>Expense</td>
<td><input type='text' name='expense' class='form-control' required></td>
</tr>
<tr>
<td>Profit</td>
<td><input name='profit' class='form-control' type = "number" id="profit" required></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
<span class="glyphicon glyphicon-plus"></span> Save this Record
</button>
</td>
</tr>
</table>
品名
客人姓名
销售日期
量
实际价格
售价
结转
卖
费用
利润
保存此记录
index.php
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Product Name</th>
<th>Actual Price</th>
<th>Sell Price</th>
<th>Stock</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
$stmt = $db_con->prepare("SELECT * FROM tblproduct ORDER BY id DESC");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['actualprice']; ?></td>
<td><?php echo $row['sellprice']; ?></td>
<td><?php echo $row['Stock']; ?></td>
<td align="center">
<a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
<table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
<thead>
<tr>
<th>Product Name</th> //selected from product management table
<th>Sale Date</th>//(user input)
<th>Quantity</th>//(user input)
<th>Actual Price</th> //price of the selected product on the management table
<th>Selling Price</th> //price of the selected product on the management table
<th>Carry Over</th> //stock from the selected product on the management table
<th>Sells</th>//selling price of the selected product on the management table * quantity(user input)
<th>Expense</th>
<th>Profit</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<?php
require_once 'dbconfig.php';
if(isset($_POST['months'])){ $months = $_POST['months']; }else { $months='';}
$stmt = $db_con->prepare("SELECT * FROM tblsales WHERE MONTH(saledate) = '".$months."' ");
//this is for the sales management for the monthly view function didn't include the my months select this post already long enough
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['pname']; ?></td>
<td><?php echo $row['saledate']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['actualprice']; ?></td>
<td><?php echo $row['sellprice']; ?></td>
<td><?php echo $row['carryO']?></td>
<td><?php echo $row['sells']?></td>
<td><?php echo $row['expense']?></td>
<td><?php echo $row['profit']; ?></td>
<td align="center">
<a id="<?php echo $row['id']; ?>" class="edit-link" href="#" title="Edit">
<img src="edit.png" width="20px" />
</a></td>
<td align="center"><a id="<?php echo $row['id']; ?>" class="delete-link" href="#" title="Delete">
<img src="delete.png" width="20px" />
</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
产品名称//从产品管理表中选择
销售日期//(用户输入)
数量//(用户输入)
实际价格//管理表上所选产品的价格
销售价格//管理表上所选产品的价格
结转//管理表上所选产品的库存
销售//管理表上所选产品的销售价格*数量(用户输入)
费用
利润
编辑
删除
在这种情况下,使用ajax是更好的方法
$.ajax({
url: "data.php",//file wich has query select to db table
data: {id:theid},//describe your data here
dataType: 'json',// type of data that will you get (JSON/HTML).
type: 'POST',//sending type (POST/GET)
success: function(data) {
showTable();
}
});