我的代码如下。我有所有表单值的字段并单击保存,但如果<?php
session_start();
include_once("../connection.php");
/*...*/
function saveData() {
$productNames = mysqli_real_escape_string($_POST['productNames']);
$productCode = mysqli_real_escape_string($_POST['productCode']);
$barcode = mysqli_real_escape_string($_POST['barcode']);
if(!empty($_POST('category'))) {
$category = mysqli_real_escape_string($_POST['category']);
}
else {
$category = "Kategori yok";
}
$starterAmount = mysqli_real_escape_string($_POST['starterAmount']);
$buyingFee = mysqli_real_escape_string($_POST['buyingFee']);
$sellingFee = mysqli_real_escape_string($_POST['sellingFee']);
$KDV = mysqli_real_escape_string($_POST['KDV']);
if(!empty($_POST('OIV'))) {
$OIV = mysqli_real_escape_string($_POST['OIV']);
}
else {
$OIV = "0,00";
}
if(!empty($_POST('sOTV'))) {
$sOTV = mysqli_real_escape_string($_POST['sOTV']);
}
else {
$sOTV = "0,00";
}
if(!empty($_POST('bOTV'))) {
$bOTV = mysqli_real_escape_string($_POST['bOTV']);
}
else {
$bOTV = "0,00";
}
if(!empty($_POST('discount'))) {
$discount = mysqli_real_escape_string($_POST['discount']);
}
else {
$discount = "0,00";
}
$tableName = "stc_def_tab_4_c_" . $companyID;
$addNew = "INSERT INTO `$tableName` (`productNames`, `productCode`, `barcode`, `category`, `starterAmount`, `buyingFee`, `sellingFee`, `KDV`, `OIV`, `sOTV`, `bOTV`, `discount`, `firstAdded`) VALUES ('$productNames', '$productCode', '$barcode', '$category', $starterAmount, $buyingFee, $sellingFee, $KDV, $OIV, $sOTV, $bOTV, $discount, CURDATE())";
if($connection->query($addNew)){
header('location: services-and-products.php');
} else{
$emsg = "ERROR: Could not able to execute $addNew. " . mysqli_error($connection);
}
}
if(isset($_POST['productNames']) & isset($_POST['productCode']) & isset($_POST['barcode']) & isset($_POST['starterAmount']) & isset($_POST['buyingFee']) & isset($_POST['sellingFee']) & isset($_POST['KDV'])) {
if(isset($_POST['Save'])) {
saveData();
}
elseif(isset($_POST['SaveCont'])) {
saveData();
}
}
else {
$emsg2 = "Fill required areas.";
}
?>
<!-- ... -->
<form action="" method="post">
<?php if(isset($emsg)){ ?>
<div class="alert alert-danger" role="alert"> <?php echo $emsg; ?></div>
<?php } ?>
<?php if(isset($emsg2)){ ?>
<div class="alert alert-danger" role="alert"> <?php echo $emsg2; ?></div>
<?php } ?>
<div class="row">
<div class="col-md-1" style="vertical-align: middle;">
<i class="glyphicon glyphicon-text-color" style="font-size:36px; padding-top: 10%; color:gray;"></i>
</div>
<div class="col-md-2">
<h6 style="padding-top: 10%; color:gray;">Adı</h6>
</div>
<div class="col-md-6">
<input type="text" name="productName" placeholder="Adı" />
</div>
</div>
<div class="row">
<div class="col-md-1" style="vertical-align: middle;">
<i class="fa fa-code" style="font-size:36px; padding-top: 10%; color:gray;"></i>
</div>
<div class="col-md-2">
<h6 style="padding-top: 10%; color:gray;">Kodu</h6>
</div>
<div class="col-md-6">
<input type="text" name="productCode" placeholder="Kodu" />
</div>
</div>
<div class="row">
<div class="col-md-1" style="vertical-align: middle;">
<i class="fa fa-barcode" style="font-size:36px; padding-top: 10%; color:gray;"></i>
</div>
<div class="col-md-2">
<h6 style="padding-top: 10%; color:gray;">Barkod</h6>
</div>
<div class="col-md-6">
<input type="text" name="barcode" placeholder="Barkod" />
</div>
<div class="col-md-3">
<button class="btn btn-warning">Barkodu Tarat</button>
</div>
</div>
<div class="row">
<div class="col-md-1" style="vertical-align: middle;">
<i class="fa fa-object-group" style="font-size:36px; padding-top: 10%; color:gray;"></i>
</div>
<div class="col-md-2">
<h6 style="padding-top: 10%; color:gray;">Kategori</h6>
</div>
<div class="col-md-6">
<input type="text" name="category" placeholder="Kategori" />
</div>
</div>
<div class="row">
<div class="col-md-1" style="vertical-align: middle;">
<i class="fa fa-cube" style="font-size:36px; padding-top: 10%; color:gray;"></i>
</div>
<div class="col-md-2">
<h6 style="padding-top: 10%; color:gray;">Başlangıç Miktarı</h6>
</div>
<div class="col-md-6">
<input type="number" name="starterAmount" placeholder="0" />
</div>
</div>
<div class="row">
<div class="col-md-1" style="vertical-align: middle;">
<i class="fa fa-sign-in" style="font-size:36px; padding-top: 10%; color:gray;"></i>
</div>
<div class="col-md-2">
<h6 style="padding-top: 10%; color:gray;">Alış Fiyatı (Vergisiz)</h6>
</div>
<div class="col-md-6">
<input type="text" name="buyingFee" placeholder="0,00" />
</div>
</div>
<div class="row">
<div class="col-md-1" style="vertical-align: middle;">
<i class="fa fa-external-link" style="font-size:36px; padding-top: 10%; color:gray;"></i>
</div>
<div class="col-md-2">
<h6 style="padding-top: 10%; color:gray;">Satış Fiyatı (Vergisiz)</h6>
</div>
<div class="col-md-6">
<input type="text" name="sellingFee" placeholder="0,00" />
</div>
</div>
<div class="row">
<div class="col-md-1" style="vertical-align: middle;">
<i class="fa fa-gavel" style="font-size:36px; padding-top: 10%; color:gray;"></i>
</div>
<div class="col-md-2">
<h6 style="padding-top: 10%; color:gray;">Vergiler</h6>
</div>
</div>
<div class="row">
<div class="col-md-1">
<h6 style="padding-top: 10%; color:gray;">KDV</h6>
</div>
<div class="col-md-2">
<input type="text" name="KDV" placeholder="0,00" />
</div>
<div class="col-md-1">
<h6 style="padding-top: 10%; color:gray;">ÖİV</h6>
</div>
<div class="col-md-2">
<input type="text" name="OIV" placeholder="0,00" />
</div>
<div class="col-md-1">
<h6 style="padding-top: 10%; color:gray;">Satış ÖTV</h6>
</div>
<div class="col-md-2">
<input type="text" name="sOTV" placeholder="0,00" />
</div>
<div class="col-md-1">
<h6 style="padding-top: 10%; color:gray;">Alış ÖTV</h6>
</div>
<div class="col-md-2">
<input type="text" name="bOTV" placeholder="0,00" />
</div>
</div>
<div class="row">
<div class="col-md-1" style="vertical-align: middle;">
<i class="fa fa-percent" style="font-size:36px; padding-top: 10%; color:gray;"></i>
</div>
<div class="col-md-2">
<h6 style="padding-top: 10%; color:gray;">İndirim</h6>
</div>
<div class="col-md-6">
<input type="text" name="discount" placeholder="İndirim" />
</div>
</div>
<div class="row">
<div class="col-md-2">
<br>
</div>
<div class="col-md-3">
<center><input type="submit" id="Save" name="Save" value="Kaydet" /></center>
<br>
</div>
<div class="col-md-2">
<br>
</div>
<div class="col-md-3">
<center><input type="submit" id="SaveCont" name="SaveCont" value="Kaydet ve Yeni Ekle" /></center>
<br>
</div>
<div class="col-md-2">
<br>
</div>
</div>
<div class="row">
<br>
</div>
</form>
但我不知道原因,则无法先进入内部。有谁可以帮助我?
{{1}}
谢谢你的帮助。
答案 0 :(得分:0)
你必须使用双&符号,单个&符号不是逻辑运算符,而是按位运算符。
http://php.net/manual/en/language.operators.logical.php http://php.net/manual/en/language.operators.bitwise.php
除此之外,代码看起来很好。为了便于阅读,我个人会使用一个isset而不是多个(isset可以同时检查多个变量)。