我使用MySql创建了以下代码,但出于某种原因,它并没有运行。
<main>
<?php
$conn = mysqli_connect("localhost","root"," ","dole") or die("Error" . mysqli_error($conn));
if(isset($_POST['voucher_details']))
{
$tran_no = isset($_POST['tran_no']);
$check_no = isset($_POST['check_no']);
$payee = isset($_POST['payee']);
$add = isset($_POST['add']);
$amount = isset($_POST['amount']);
$amountw = isset($_POST['amountw']);
$obj_code = isset($_POST['obj_code']);
$payment = isset($_POST['payment']);
$div_no = isset($_POST['div_no']);
$sql="INSERT INTO tbl_gip VALUES ('tran_no','obj_code','check_no','div_no','payee','payment','add','amount','amountw') ('{$tran_no}','{$obj_code}','{$check_no}','{$div_no}','{$payee}','{$payment}','{$add}','{$amount}','{$amountw}')";
}
?>
<section>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="voucher_details">
<div id="form">
<input class="form-control" name="tran_no" type="number" placeholder="Transcation No." readonly><br>
<input class="form-control" name="obj_code" type="text" placeholder="Object-Code"><br>
<input class="form-control" name="check_no" type="text" placeholder="Check No."><br>
<input class="form-control" name="div_no" type="text" placeholder="DIV-no"><br>
<input class="form-control" name="payee" type="text" placeholder="Payee"><br>
<input class="form-control" name="payment" type="text" placeholder="Nature of Payment">br>
<input class="form-control" name="add" type="text" placeholder="Address"><br>
<input class="form-control" name="amount" type="text" placeholder="Amount"><br>
<input class="form-control" name="amountw" type="text" placeholder="Amount in Words" readonly><br>
<button type="submit" class="btn btn-success" name="save" id="save">Save</button>
</div>
</form>
它不会返回任何错误,但我认为此代码不起作用。有人可以解释我犯的错误,怎么没有错误出现?
答案 0 :(得分:2)
您已在数据库中创建了插入查询,但您没有运行它。
你必须改为:
$sql="INSERT INTO tbl_gip VALUES ('tran_no','obj_code','check_no','div_no','payee','payment','add','amount','amountw') ('{$tran_no}','{$obj_code}','{$check_no}','{$div_no}','{$payee}','{$payment}','{$add}','{$amount}','{$amountw}')";
mysqli_query($conn, $sql);
答案 1 :(得分:0)
最有可能的候选人是无效的缩进。 <?php
结束标记未正确缩进。因此,这将使执行程序将整个事物假设为PHP(我不确定如此,但这是JavaScript中的情况所发生的情况)。
<?php
//Content here
?>
答案 2 :(得分:0)
您的变量是错误的,您应该过滤它们,并且您需要执行查询。将其更改为:
<?php
$conn = mysqli_connect("localhost","root"," ","dole") or die("Error" . mysqli_error($conn));
if(isset($_POST['voucher_details'])){
//instead of $POST['var'], use filter_input(INPUT_POST,'var',{filter_type}),
//same goes for $_GET['var']...use filter_input(INPUT_GET,'var',{filter_type})
$tran_no = filter_input(INPUT_POST,'tran_no',FILTER_VALIDATE_INT);
//...continue to filter each $var based on type;FILTER_VALIDATE_INT for ints, FILTER_SANITIZE_STRING for strings, etc.
//Also note that your 'values' clause was in the wrong spot as well
$sql="INSERT INTO tbl_gip (tran_no,obj_code,check_no,div_no,payee,payment,add,amount,amountw) VALUES ('{$tran_no}','{$obj_code}','{$check_no}','{$div_no}','{$payee}','{$payment}','{$add}','{$amount}','{$amountw}')";
mysqli_query($conn, $sql);
}
?>