我想在按下按钮时添加记录。这是我的PHP:
<?php
$date="";
$category_value="";
$item_value="";
$vendor_value="";
$unit_value="";
$price_rate_value="";
$quantity_value="";
$vat_value="";
$freight_value="";
$other_charges_value="";
$total_value="";
if( !empty($_POST['category']) && !empty($_POST['item_name']) &&!empty($_POST['vendor_name']) && !empty($_POST['Unit']) && !empty($_POST['Price_per_Unit']) && !empty($_POST['Quantity']) && !empty($_POST['VAT']) && !empty($_POST['Freight_charges'])&& !empty($_POST['Other_Charges']))
{
//$date=$_POST['datepicker'];
$category_value=$_POST['category'];
$item_value=$_POST['item_name'];
$vendor_value=$_POST['vendor_name'];
$unit_value=$_POST['Unit'];
$price_rate_value=$_POST['Price_per_Unit'];
$quantity_value=$_POST['Quantity'];
$vat_value=$_POST['VAT'];
$freight_value=$_POST['Freight_charges'];
$other_charges_value=$_POST['Other_Charges'];
$total_value=$price_rate_value * $quantity_value;
$sth = $conn->prepare('INSERT INTO bill (date, category, item, vendor, unit, price_per_unit, quantity, vat, freight_charges, other_charges, total) VALUES (CURRENT_DATE, :category, :item, :vendor, :unit, :rate, :quantity, :vat, :freight, :other, :total)');
$sth->execute(array(':category'=>$category_value,':item'=>$item_value,':vendor'=>$vendor_value,':unit'=>$unit_value,':rate'=>$price_rate_value,':quantity'=>$quantity_value,':vat'=>$vat_value,':freight'=>$freight_value,':other'=>$other_charges_value,':total'=>$total_value));
header( "Refresh: 0;" );}
?>
这是我的HTML:
<form method="POST">
<input type="submit" name="submit" value="Update" style="width:150px;padding:10px;">
以下是连接代码:
<?php
$servername = "localhost";
$conusername = "root";
$conpassword = "";
$dbname = "annapoorna";
$dsn='mysql:dbname='.$dbname.';host='.$servername;
$conn = new PDO($dsn, $conusername, $conpassword);
?>
单击按钮时,未插入记录。这是为什么? 我多次检查过,但是徒劳无功。