我的数据库中有两个表fournisseur(提供者)和facture(bill)。
我想通过选择我的选项列表中的提供商及其付款来插入所选提供商的帐单,然后填写表单并单击提交以将提供商的帐单数据保存到他的表帐单中。 bill form
当我运行表单并填写表单然后单击ajouter(添加)该错误显示error display after click on add
这是我的PHP代码,用于处理数据并将其保存到数据库中:
<?php
include 'function/db.php';
if (isset($_POST['selection_fourni']) && isset($_POST['selection_mod_reg'])) {
$selection_fourni = $_POST['selection_fourni'];
$selection_mod_reg = $_POST['selection_mod_reg'];
}
if (isset($_POST['ajouter'])) {
$num_fac = $_POST['num_facn'];
$date_depn = $_POST['date_depn'];
$date_echn = $_POST['date_echn'];
$chercher = $db -> prepare('SELECT * FROM facture WHERE id_fourni = :idfourni AND id_mod_reg = :idmodreg');
$chercher -> execute(array('idfourni' => $selection_fourni, 'idmodreg' => $selection_mod_reg));
if ($chercher) {
$ajouter_fac = $db -> prepare('INSERT INTO facture (num_fac, date_depot, date_ech) VALUES (:numfac, :datedepot, :dateech) WHERE id_fourni = :idfourni AND id_mod_reg = :idmodreg');
$ajouter_fac -> execute(array( 'numfac' => $num_fac, 'datedepot' => $date_depn, 'dateech' => $date_echn, 'idfourni' => $selection_fourni, 'idmodreg' => $selection_mod_reg));
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- ============================== css ==============================================-->
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<!-- =================================================================================-->
<title>Fournisseur</title>
</head>
<body>
<div class="container">
<nav class="navbar navbar-default"><!-- début de la barre de navigation -->
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#"><b> QuickCash: </b>Application comptable</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<!-- **************** LEFT SIDE NAV **********************************-->
<ul class="nav navbar-nav">
<li><a href="fournisseurA.php">Fournisseur</a></li>
<li><a href="#">Mode de reglement</a></li>
<li class="active"><a href="factureA.php">Facture</a></li>
</ul>
<!-- *****************************************************************-->
<!-- **************** RIGHT SIDE NAV ***********************-->
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="factureA.php">Ajouter</a></li>
<li><a href="factureM.php">Modifier</a></li>
<li><a href="factureS.php">Supprimer</a></li>
</ul>
<!-- *******************************************************-->
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
<div class="jumbotron">
<form method="post">
<div class="row">
<ul class="nav navbar-nav">
<li>
<label for="id_fourni"> Selectionner le fournisseur</label>
<select class="form-control" name="selection_fourni" id="id_fourni">
<?php
$list_fourni = $db -> query('SELECT * FROM fournisseur');
while ($data = $list_fourni -> fetch()) {
?>
<option value="<?php echo $data['id_fourni']; ?>"><?php echo $data['nom_fourni']; ?></option>
<?php
}
?>
</select>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<label for="id_fourni"> Selectionner son mode de paiement</label>
<select class="form-control" name="selection_mod_reg" id="id_fourni">
<?php
$list_mod_reg = $db -> query('SELECT * FROM mode_reglement');
while ($data = $list_mod_reg -> fetch()) {
?>
<option value="<?php echo $data['id_mod_reg']; ?>"><?php echo $data['libelle_mod']; ?></option>
<?php
}
?>
</select>
</li>
</ul>
</div>
<br>
<br>
<div class="form-group">
<label for="num_fac">Numero facture</label>
<input type="text" class="form-control" id="num_fac" name="num_facn" placeholder="Entrez le numero de la facture">
</div>
<div class="form-group">
<label for="date_dep">Date depot</label>
<input type="date" class="form-control" id="date_dep" name="date_depn">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Date echéance</label>
<input type="date" class="form-control" id="date_ech" name="date_echn">
</div>
<ul class="nav navbar-nav">
<li><button type="submit" class="btn btn-success" name="ajouter">Ajouter</button></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><button type="reset" class="btn btn-danger" name="Annuler">Annuler</button></li>
</ul>
</form>
</div>
</div>
<!-- ========================================= Javascript ======================================== -->
<script type="text/javascript" src="js/jquery-3.1.1.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>
<!-- ============================================================================================= -->
</body>
</html><?php
include 'function/db.php';
if (isset($_POST['selection_fourni']) && isset($_POST['selection_mod_reg'])) {
$selection_fourni = $_POST['selection_fourni'];
$selection_mod_reg = $_POST['selection_mod_reg'];
}
if (isset($_POST['ajouter'])) {
$num_fac = $_POST['num_facn'];
$date_depn = $_POST['date_depn'];
$date_echn = $_POST['date_echn'];
$chercher = $db -> prepare('SELECT * FROM facture WHERE id_fourni = :idfourni AND id_mod_reg = :idmodreg');
$chercher -> execute(array('idfourni' => $selection_fourni, 'idmodreg' => $selection_mod_reg));
if ($chercher) {
$ajouter_fac = $db -> prepare('INSERT INTO facture (num_fac, date_depot, date_ech) VALUES (:numfac, :datedepot, :dateech) WHERE id_fourni = :idfourni AND id_mod_reg = :idmodreg');
$ajouter_fac -> execute(array( 'numfac' => $num_fac, 'datedepot' => $date_depn, 'dateech' => $date_echn, 'idfourni' => $selection_fourni, 'idmodreg' => $selection_mod_reg));
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- ============================== css ==============================================-->
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<!-- =================================================================================-->
<title>Fournisseur</title>
</head>
<body>
<div class="container">
<nav class="navbar navbar-default"><!-- début de la barre de navigation -->
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#"><b> QuickCash: </b>Application comptable</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<!-- **************** LEFT SIDE NAV **********************************-->
<ul class="nav navbar-nav">
<li><a href="fournisseurA.php">Fournisseur</a></li>
<li><a href="#">Mode de reglement</a></li>
<li class="active"><a href="factureA.php">Facture</a></li>
</ul>
<!-- *****************************************************************-->
<!-- **************** RIGHT SIDE NAV ***********************-->
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="factureA.php">Ajouter</a></li>
<li><a href="factureM.php">Modifier</a></li>
<li><a href="factureS.php">Supprimer</a></li>
</ul>
<!-- *******************************************************-->
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
<div class="jumbotron">
<form method="post">
<div class="row">
<ul class="nav navbar-nav">
<li>
<label for="id_fourni"> Selectionner le fournisseur</label>
<select class="form-control" name="selection_fourni" id="id_fourni">
<?php
$list_fourni = $db -> query('SELECT * FROM fournisseur');
while ($data = $list_fourni -> fetch()) {
?>
<option value="<?php echo $data['id_fourni']; ?>"><?php echo $data['nom_fourni']; ?></option>
<?php
}
?>
</select>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<label for="id_fourni"> Selectionner son mode de paiement</label>
<select class="form-control" name="selection_mod_reg" id="id_fourni">
<?php
$list_mod_reg = $db -> query('SELECT * FROM mode_reglement');
while ($data = $list_mod_reg -> fetch()) {
?>
<option value="<?php echo $data['id_mod_reg']; ?>"><?php echo $data['libelle_mod']; ?></option>
<?php
}
?>
</select>
</li>
</ul>
</div>
<br>
<br>
<div class="form-group">
<label for="num_fac">Numero facture</label>
<input type="text" class="form-control" id="num_fac" name="num_facn" placeholder="Entrez le numero de la facture">
</div>
<div class="form-group">
<label for="date_dep">Date depot</label>
<input type="date" class="form-control" id="date_dep" name="date_depn">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Date echéance</label>
<input type="date" class="form-control" id="date_ech" name="date_echn">
</div>
<ul class="nav navbar-nav">
<li><button type="submit" class="btn btn-success" name="ajouter">Ajouter</button></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><button type="reset" class="btn btn-danger" name="Annuler">Annuler</button></li>
</ul>
</form>
</div>
</div>
<!-- ========================================= Javascript ======================================== -->
<script type="text/javascript" src="js/jquery-3.1.1.js"></script>
<script type="text/javascript" src="bootstrap.js"></script>
<!-- ============================================================================================= -->
</body>
</html>
答案 0 :(得分:0)
我将插入更改为SQL
$ajouter_fac = $db -> prepare('INSERT INTO facture (num_fac, date_depot, date_ech, id_fourni, id_mod_reg) VALUES (:numfac, :datedepot, :dateech, :idfourni, :idmodreg)');
$ajouter_fac -> execute(array( 'numfac' => $num_fac, 'datedepot' => $date_depn, 'dateech' => $date_echn, 'idfourni' => $selection_fourni, 'idmodreg' => $selection_mod_reg));
我希望它可以帮助其他有需要的人。
由于