由于我的问题被标记为重复,我必须对我的问题给出更多解释。我已经完成了一天的搜索和阅读。所有答案都建议使用我已经使用过的isset
。但是,由于我缺乏知识,我无法弄清楚我的问题的真正原因。然后我希望我能在这里获得一些帮助,技能和更多的知识。
我创建了一个页面,使用表格将数据发送到DB上的库存表中的7列。当我检查数据库上的数据时,只有5列获取数据,而对于列平衡和总计,我得到0作为值。然后我尝试使用error_reporting(E_ALL);
ini_set('display_errors', '1');
进行调试。
以下是错误:
Notice: Undefined index: balance in C:\xampp\unixa\module\stock\stockout.php on line 29
Notice: Undefined index: totalout in C:\xampp\unixa\module\stock\stockout.php on line 30
这是我的代码:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$Conn = ConnDB();
// $Conn->debug=true;
$id = htmlentities($_POST['id'], ENT_QUOTES);
$sql = "SELECT
inventories.id,
inventories.categories,
brands.`name` AS brandname,
inventories.model,
inventories.qty,
inventories.datein,
inventories.invoice,
inventories.price
FROM inventories
INNER JOIN brands ON brands.id = inventories.brand_id
WHERE
inventories.id = '$id'";
$rs = $Conn->execute($sql);
if(isset($_POST['submit'])){
$machineid = htmlentities($_POST['machineid'], ENT_QUOTES);
$qty = htmlentities($_POST['qty'], ENT_QUOTES);
$balance = htmlentities($_POST['balance'], ENT_QUOTES);
$totalout = htmlentities($_POST['totalout'], ENT_QUOTES);
$dateout = htmlentities($_POST['dateout'], ENT_QUOTES);
$id = htmlentities($_POST['id'], ENT_QUOTES);
$sql3 = "INSERT INTO stockout (inventorie_id, machines_id, qty, balance, totalout, dateout)
VALUES ('$id', '$machineid', '$qty', '$balance', '$totalout', '$dateout')";
$rs3 = $Conn->execute($sql3);
echo "<div class=\"alert alert-success alert-dismissable\">
<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>
<strong>Add stock out successfully</strong>
</div>";
}
?>
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker({
format: 'YYYY-MM-DD'
});
});
function calculateTotal() {
var totalAmt = document.stockout.qty.value;
totalR = eval(totalAmt * document.inventories.price.value);
document.getElementById('totalout').value = totalR;
};
</script>
<div class="container-fluid bg-3">
<h4>Stock Out</h4>
<br>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="category">Category:</label>
<input type="text" class="form-control" placeholder="<?php echo $rs->fields['categories'] ?>" disabled />
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="brand">Brand:</label>
<input type="text" class="form-control" placeholder="<?php echo $rs->fields['brandname'] ?>" disabled />
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="model">Model:</label>
<input type="text" class="form-control" placeholder="<?php echo $rs->fields['model'] ?>" disabled />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="datein">Date In:</label>
<input type="text" class="form-control" placeholder="<?php echo $rs->fields['datein'] ?>" disabled />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="invoiceno">Invoice No:</label>
<input type="text" class="form-control" placeholder="<?php echo $rs->fields['invoice'] ?>" disabled />
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="qty">Quantity:</label>
<input type="text" class="form-control" placeholder="<?php echo $rs->fields['qty'] ?>" disabled />
</div>
</div>
<form name="inventories" action="" id="inventories" >
<div class="col-md-6">
<div class="form-group">
<label for="price">Price per Unit (RM):</label>
<input type="text" class="form-control" id="price" name="price" onclick="calculateTotal()" onkeyup="calculateTotal()" value="<?php echo $rs->fields['price'] ?>" disabled />
</div>
</div>
</form>
</div>
</form>
<form data-toggle="validator" method="post" action="" name="stockout" action="" id="stockout">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label for="machineid"><font color="red"></font> Machine ID:</label>
<select class="form-control" id="machineid" name="machineid" />
<option value="">Please select</option>
<?php
$sql2 = "SELECT * FROM machines ORDER BY id";
$rs2 = $Conn->execute($sql2);
while(!$rs2->EOF){
?>
<option value="<?php echo $rs2->fields['id'] ?>"><?php echo $rs2->fields['id'] ?></option>
<?php
$rs2->moveNext(); }
?>
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="qty"><font color="red">*</font> Quantity Out:</label>
<input type="text" name="qty" class="form-control" onchange="calculateTotal()" onclick="calculateTotal()" id="qty" name="qty" required />
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="balance">Balance:</label>
<?php
$stockqty = $rs->fields['id'];
$sql2 = "SELECT SUM(qty) AS total FROM stockout WHERE inventorie_id='$stockqty'";
$rs2 = $Conn->execute($sql2);
?>
<input type="text" name="balance" class="form-control" id="balance" placeholder="<?php echo $rs->fields['qty'] - $rs2->fields['total']; ?>" disabled />
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="totalout">Amount (RM):</label>
<input type="text" class="form-control" id="totalout" name="totalout" disabled />
</div>
</div>
<div class="col-md-4">
<label for="dateout"><font color="red">*</font> Date Out:</label>
<div class='input-group date' id='datetimepicker1' style="color:black">
<input type='text' class="form-control" id="dateout" name="dateout" required />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<input type="hidden" class="form-control" id="id" name="id" value="<?php echo $rs->fields['id'] ?>"/>
</div>
<input id="submit" name="submit" type="submit" value="Add" class="btn btn-primary pull-right">
</form>
</div>
我是初学者,我的大部分代码都来自互联网。希望你们能帮助我修复声明变量。感谢。