Php 插入记录时出错
我不太擅长编码,我想知道是否有人能帮我。我正在使用PHP/MYSQL创建一个包含单选按钮和下拉列表的表单。 当我尝试测试和插入记录时,它会说 “抱歉!插入记录时出错!” 这是我的代码 dbconfig.phpPhp 插入记录时出错,php,html,mysql,Php,Html,Mysql,我不太擅长编码,我想知道是否有人能帮我。我正在使用PHP/MYSQL创建一个包含单选按钮和下拉列表的表单。 当我尝试测试和插入记录时,它会说 “抱歉!插入记录时出错!” 这是我的代码 dbconfig.php <?php $DB_host = "localhost"; $DB_user = "root"; $DB_pass = ""; $DB_name = "dblogin"; try { $DB_con = new PDO("mysql:host={$DB_host};d
<?php
$DB_host = "localhost";
$DB_user = "root";
$DB_pass = "";
$DB_name = "dblogin";
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();
}
include_once 'class.crud.php';
$crud = new crud($DB_con);
?>
add-data.php
<?php
include_once 'dbconfig.php';
if(isset($_POST['btn-save']))
{
$FteName = $_POST['FteName'];
$SalesMgr = $_POST['SalesMgr'];
$GEO = $_POST['GEO'];
$ProdMgr = $_POST['ProdMgr'];
$AeName = $_POST['AeName'];
$CustName = $_POST['CustName'];
$CustCat = $_POST['CustCat'];
$CustPoNum = $_POST['CustPoNum'];
$CustPoDate = $_POST['CustPoDate'];
$SalesQrt = $_POST['SalesQrt'];
$PaymentStat = $_POST['PaymentStat'];
$SONum = $_POST['SONum'];
$AmtPaid = $_POST['AmtPaid'];
$DatePaid = $_POST['DatePaid'];
$OppoGold = $_POST['OppoGold'];
$CheckBy = $_POST['CheckBy'];
if($crud->create($FteName=$SalesMgr=$GEO=$ProdMgr=$AeName=$CustName=$CustCat=$CustPoNum=$CustPoDate=$SalesQrt=$PaymentStat=$SONum=$AmtPaid=$DatePaid=$OppoGold=$CheckBy))
{
header("Location: add-data.php?inserted");
}
else
{
header("Location: add-data.php?failure");
}
}
?>
<?php include_once 'header.php'; ?>
<div class="clearfix"></div>
<?php
if(isset($_GET['inserted']))
{
?>
<div class="container">
<div class="alert alert-info">
<strong>Data successfully save. </strong><a href="index.php">HOME</a>!
</div>
</div>
<?php
}
else if(isset($_GET['failure']))
{
?>
<div class="container">
<div class="alert alert-warning">
<strong>SORRY!</strong> ERROR while inserting record !
</div>
</div>
<?php
}
?>
<div class="clearfix"></div><br />
<div class="container">
<form method='post'>
<table class='table table-bordered'>
<tr>
<td>FTE/SR Name:</td>
<td><input type='text' name='FteName' class='form-control' required></td>
</tr>
<tr>
<td>Sales Manager/Team Leader</td>
<td><input type='text' name='SalesMgr' class='form-control' required></td>
</tr>
<tr>
<td>GEO</td>
<td><input type='text' name='GEO' class='form-control' required></td>
</tr>
<tr>
<td>AE (Presales)</td>
<td><input type='text' name='AeName' class='form-control' required></td>
</tr>
<tr>
<td>Customer Name</td>
<td><input type='text' name='CustName' class='form-control' required></td>
</tr>
<tr>
<td>Customer Category</td>
<td><select name='CustCat' class='form-control' required>
<option value="New">New</option>
<option value="Installed Base">Installed Base</option>
<option value="DS-Reffered">DS Reffered</option>
<option value="DS-Old">DS-Old</option>
</select></td>
</tr>
<tr>
<td>Custom PO Number</td>
<td><input type='text' name='CustPoNum' class='form-control' required></td>
</tr>
<tr>
<td>Customer PO Date</td>
<td><input type='text' name='CustPoDate' class='form-control' required></td>
</tr>
<tr>
<td>SO Number</td>
<td><input type='text' name='SONum' class='form-control' required></td>
</tr>
<tr>
<td>Sales for Quarter</td>
<td><Input type = 'Radio' Name ='SalesQrt' value= '1st Quarter' />1st Quarter
<Input type = 'Radio' Name ='SalesQrt' value= '2nd Quarter' />2nd Quarter
<Input type = 'Radio' Name ='SalesQrt' value= '3rd Quarter' />3rd Quarter
<Input type = 'Radio' Name ='SalesQrt' value= '4th Quarter' />4th Quarter</td>
</tr>
<tr>
<td>Payment Status</td>
<td><Input type = 'Radio' Name ='PaymentStat' value= 'Yes' />Yes
<Input type = 'Radio' Name ='PaymentStat' value= 'No' />No</td>
</tr>
<tr>
<td>Amount Paid</td>
<td><input type='text' name='AmtPaid' class='form-control' required></td>
</tr>
<tr>
<td>Date Paid</td>
<td><input type='text' name='DatePaid' class='form-control' required></td>
</tr>
<tr>
<td>Enter in Goldmine?</td>
<td><Input type = 'Radio' Name ='OppoGold' value= 'Yes' />Yes
<Input type = 'Radio' Name ='OppoGold' value= 'No' />No</td>
</tr>
<tr>
<td>Verified/Checked By:</td>
<td><input type='text' name='CheckBy' class='form-control' required></td>
</tr>
<tr>
<td colspan="2">
<button type="submit" class="btn btn-primary" name="btn-save">
<span class="glyphicon glyphicon-plus"></span> SAVE
</button>
<a href="index.php" class="btn btn-large btn-success"><i class="glyphicon glyphicon-backward"></i> Back to index</a>
</td>
</tr>
</table>
</form>
</div>
数据成功保存强>!
对不起插入记录时出错!
全职员工/高级职员姓名:
销售经理/团队负责人
地理位置
AE(售前)
客户名称
客户类别
新的
安装基数
参考DS
旧的
定制订单号
客户订单日期
这么多
季度销售额
第一季度
第二季度
第三季度
第四季度
支付状态
对
不
已付金额
支付日期
进入金矿?
对
不
验证/检查人:
拯救
class.crud.php
类积垢
{
private $db;
function __construct($DB_con)
{
$this->db = $DB_con;
}
public function create($FteName,$SalesMgr,$GEO,$ProdMgr,$AeName,$CustName,$CustCat,$CustPoNum,$CustPoDate,$SalesQrt,$SONum,$AmtPaid,$AmtDatePaid,$OppoGold,$CheckBy)
{
try
{
$stmt = $this->db->prepare("INSERT INTO info(FteName,SalesMgr,GEO,ProdMgr,AeName,CustName,CustCat,CustPoNum,CustPoDate,SalesQrt,SONum,AmtPaid,AmtDatePaid,OppoGold,CheckBy) VALUES(:FteName, :SalesMgr, :GEO, :ProdMgr, :AeName, :CustName, :CustCat, :CustPoNum, :CustPoDate, :SalesQrt, :SONum, :AmtPaid, :AmtDatePaid, :OppoGold, :CheckBy)");
$stmt->bindparam(":FteName",$FteName);
$stmt->bindparam(":SalesMgr",$SalesMgr);
$stmt->bindparam(":GEO",$GEO);
$stmt->bindparam(":ProdMgr",$ProdMgr);
$stmt->bindparam(":AeName",$AeName);
$stmt->bindparam(":CustName",$CustName);
$stmt->bindparam(":CustCat",$CustCat);
$stmt->bindparam(":CustPoNum",$CustPoNum);
$stmt->bindparam(":CustPoDate",$CustPoDate);
$stmt->bindparam(":SalesQrt",$SalesQrt);
$stmt->bindparam(":SONum",$SONum);
$stmt->bindparam(":AmtPaid",$AmtPaid);
$stmt->bindparam(":AmtDatePaid",$AmtDatePaid);
$stmt->bindparam(":OppoGold",$OppoGold);
$stmt->bindparam(":CheckBy",$CheckBy);
$stmt->execute();
return true;
}
catch(PDOException $e)
{
echo $e->getMessage();
return false;
}
}
public function getID($infoID)
{
$stmt = $this->db->prepare("SELECT * FROM info WHERE infoID=:infoID");
$stmt->execute(array(":infoID"=>$infoID));
$editRow=$stmt->fetch(PDO::FETCH_ASSOC);
return $editRow;
}
public function update($infoID,$FteName,$SalesMgr,$GEO,$ProdMgr,$AeName,$CustName,$CustCat,$CustPoNum,$CustPoDate,$SalesQrt,$SONum,$AmtPaid,$AmtDatePaid,$OppoGold,$CheckBy)
{
try
{
$stmt=$this->db->prepare("UPDATE info SET FteName=:FteName,
SalesMgr=:SalesMgr,
GEO=:GEO,
ProdMgr=:ProdMgr,
AeName=:AeName,
CustName=:CustName,
CustCat=:CustCat,
CustPoNum=:CustPoNum,
CustPoDate=:CustPoDate,
SalesQrt=:SalesQrt,
SONum=:SONum,
AmtPaid=:AmtPaid,
AmtDatePaid=:AmtDatePaid,
OppoGold=:OppoGold,
CheckBy=:CheckBy
WHERE infoID=:infoID ");
$stmt->bindparam(":FteName",$FteName);
$stmt->bindparam(":SalesMgr",$SalesMgr);
$stmt->bindparam(":GEO",$GEO);
$stmt->bindparam(":ProdMgr",$ProdMgr);
$stmt->bindparam(":AeName",$AeName);
$stmt->bindparam(":CustName",$CustName);
$stmt->bindparam(":CustCat",$CustCat);
$stmt->bindparam(":CustPoNum",$CustPoNum);
$stmt->bindparam(":CustPoDate",$CustPoDate);
$stmt->bindparam(":SalesQrt",$SalesQrt);
$stmt->bindparam(":SONum",$SONum);
$stmt->bindparam(":AmtPaid",$AmtPaid);
$stmt->bindparam(":AmtDatePaid",$AmtDatePaid);
$stmt->bindparam(":OppoGold",$OppoGold);
$stmt->bindparam(":CheckBy",$CheckBy);
$stmt->execute();
return true;
}
catch(PDOException $e)
{
echo $e->getMessage();
return false;
}
}
public function delete($infoID)
{
$stmt = $this->db->prepare("DELETE FROM info WHERE infoID=:infoID");
$stmt->bindparam(":infoID",$infoID);
$stmt->execute();
return true;
}
/* paging */
public function dataview($query)
{
$stmt = $this->db->prepare($query);
$stmt->execute();
if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php print($row['FteName']); ?></td>
<td><?php print($row['ProdMgr']); ?></td>
<td><?php print($row['CustName']); ?></td>
<td><?php print($row['CustPoNum']); ?></td>
<td><?php print($row['CustPoDate']); ?></td>
<td align="center">
<a href="../PDO-OOP-CRUD-with-Bootstrap/edit-data.php?edit_id=<?php print($row['infoID']); ?>"><i class="glyphicon glyphicon-edit"></i></a>
</td>
<td align="center">
<a href="../PDO-OOP-CRUD-with-Bootstrap/delete.php?delete_id=<?php print($row['infoID']); ?>"><i class="glyphicon glyphicon-remove-circle"></i></a>
</td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td>Nothing here...</td>
</tr>
<?php
}
}
public function paging($query,$records_per_page)
{
$starting_position=0;
if(isset($_GET["page_no"]))
{
$starting_position=($_GET["page_no"]-1)*$records_per_page;
}
$query2=$query." limit $starting_position,$records_per_page";
return $query2;
}
public function paginglink($query,$records_per_page)
{
$self = $_SERVER['PHP_SELF'];
$stmt = $this->db->prepare($query);
$stmt->execute();
$total_no_of_records = $stmt->rowCount();
if($total_no_of_records > 0)
{
?><ul class="pagination"><?php
$total_no_of_pages=ceil($total_no_of_records/$records_per_page);
$current_page=1;
if(isset($_GET["page_no"]))
{
$current_page=$_GET["page_no"];
}
if($current_page!=1)
{
$previous =$current_page-1;
echo "<li><a href='".$self."?page_no=1'>First</a></li>";
echo "<li><a href='".$self."?page_no=".$previous."'>Previous</a></li>";
}
for($i=1;$i<=$total_no_of_pages;$i++)
{
if($i==$current_page)
{
echo "<li><a href='".$self."?page_no=".$i."' style='color:red;'>".$i."</a></li>";
}
else
{
echo "<li><a href='".$self."?page_no=".$i."'>".$i."</a></li>";
}
}
if($current_page!=$total_no_of_pages)
{
$next=$current_page+1;
echo "<li><a href='".$self."?page_no=".$next."'>Next</a></li>";
echo "<li><a href='".$self."?page_no=".$total_no_of_pages."'>Last</a></li>";
}
?></ul><?php
}
}
/* paging */
}
{
私人$db;
函数构造($DB\u con)
{
$this->db=$db\u con;
}
公共函数创建($FteName、$SALESSMGR、$GEO、$ProdMgr、$AeName、$CustName、$CustCat、$CustPoNum、$CustPoDate、$SalesQrt、$SONum、$AmtPaid、$AMTDATEPADED、$OppoGold、$CheckBy)
{
尝试
{
$stmt=$this->db->prepare(“插入信息(FteName、SalesMgr、GEO、ProdMgr、AeName、CustName、CustCat、custpoate、saleqrt、SONum、AmtPaid、AmtDatePaid、OppoGold、CheckBy)值(:FteName、:SalesMgr、:GEO、:ProdMgr、:AeName、:CustCat、:custpoant、:custpoant、:saleqrt、:SONum、:AmtPaid、:AmtDatePaid、:OppoGold、:CheckBy)”);
$stmt->bindparam($FteName“,$FteName);
$stmt->bindparam(“:SalesMgr”,“$SalesMgr”);
$stmt->bindparam(“:GEO”,$GEO);
$stmt->bindparam(“:ProdMgr”,“$ProdMgr”);
$stmt->bindparam(“:AeName”,$AeName);
$stmt->bindparam(“:CustName”,$CustName);
$stmt->bindparam(“:CustCat”,$CustCat);
$stmt->bindparam(“:CustPoNum”,$CustPoNum);
$stmt->bindparam(“:CustPoDate”,$CustPoDate);
$stmt->bindparam(“:SalesQrt”,“$SalesQrt”);
$stmt->bindparam(“:SONum”,$SONum);
$stmt->bindparam(“:AmtPaid”,$AmtPaid);
$stmt->bindparam(“:AmtDatePaid”,$AmtDatePaid);
$stmt->bindparam(“:OppoGold”,$OppoGold);
$stmt->bindparam(“:CheckBy”,$CheckBy);
$stmt->execute();
返回true;
}
捕获(PDO$e)
{
echo$e->getMessage();
返回false;
}
}
公共函数getID($infoID)
{
$stmt=$this->db->prepare(“从infoID=:infoID的信息中选择*);
$stmt->execute(数组(“:infoID”=>$infoID));
$editRow=$stmt->fetch(PDO::fetch_ASSOC);
返回$editRow;
}
公共功能更新($infoID、$FteName、$SalesMgr、$GEO、$ProdMgr、$AeName、$CustName、$CustCat、$CustPoNum、$CustPoDate、$SalesQrt、$SONum、$AmtPaid、$AMTDATEPADED、$OppoGold、$CheckBy)
{
尝试
{
$stmt=$this->db->prepare(“更新信息集FteName=:FteName,
SalesMgr=:SalesMgr,
GEO=:GEO,
ProdMgr=:ProdMgr,
AeName=:AeName,
CustName=:CustName,
CustCat=:CustCat,
CustPoNum=:CustPoNum,
CustPoDate=:CustPoDate,
SalesQrt=:SalesQrt,
SONum=:SONum,
AmtPaid=:AmtPaid,
AmtDatePaid=:AmtDatePaid,
OppoGold=:OppoGold,
CheckBy=:CheckBy
其中infoID=:infoID“;
$stmt->bindparam($FteName“,$FteName);
$stmt->bindparam(“:SalesMgr”,“$SalesMgr”);
$stmt->bindparam(“:GEO”,$GEO);
$stmt->bindparam(“:ProdMgr”,“$ProdMgr”);
$stmt->bindparam(“:AeName”,$AeName);
$stmt->bindparam(“:CustName”,$CustName);
$stmt->bindparam(“:CustCat”,$CustCat);
$stmt->bindparam(“:CustPoNum”,$CustPoNum);
$stmt->bindparam(“:CustPoDate”,$CustPoDate);
$stmt->bindparam(“:SalesQrt”,“$SalesQrt”);
$stmt->bindparam(“:SONum”,$SONum);
$stmt->bindparam(“:AmtPaid”,$AmtPaid);
$stmt->bindparam(“:AmtDatePaid”,$AmtDatePaid);
$stmt->bindparam(“:OppoGold”,$OppoGold);
$stmt->bindparam(“:CheckBy”,$CheckBy);
$stmt->execute();
返回true;
}
if($crud->create($FteName=$SalesMgr=$GEO=$ProdMgr=$AeName=$CustName=$CustCat=$CustPoNum=$CustPoDate=$SalesQrt=$PaymentStat=$SONum=$AmtPaid=$DatePaid=$OppoGold=$CheckBy))
if($crud->create($FteName, $SalesMgr, $GEO, $ProdMgr, $AeName, $CustName, $CustCat, $CustPoNum,
$CustPoDate, $SalesQrt, $PaymentStat, $SONum, $AmtPaid, $DatePaid, $OppoGold, $CheckBy))