эта проблема, когда я выполняю форму, она ничего не отправляет в базу данных, если я вставляю напрямую: 4product = new produit (0), она работает, поэтому я не могу отправить переменную через если это выполнимо.передать переменные из HTML-формы в экземпляр класса php
<div class="bs-example">
<h1>Ajouter un produit</h1>
<form action="../produit_insert_form.php" method="POST" class="form-horizontal" >
<div class="form-group">
<label class="control-label col-xs-3" for="code_p">ID de produit:</label>
<div class="col-xs-9">
<input type="text" class="form-control" id="code_p" placeholder="ID">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-3" for="design">Designation:</label>
<div class="col-xs-9">
<input type="text" class="form-control" id="design" placeholder="Designation">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-3" for="type">TYPE:</label>
<div class="col-xs-9">
<input type="text" class="form-control" id="type" placeholder="TYPE">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-3" for="qte">QTE:</label>
<div class="col-xs-9">
<input type="text" class="form-control" id="qte" placeholder="QTE">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-3" for="prix">PRIX:</label>
<div class="col-xs-9">
<input type="text" class="form-control" id="prix" placeholder="PRIX">
</div>
</div>
<br>
<div class="form-group">
<div class="col-xs-offset-3 col-xs-9">
<input type="submit" class="btn btn-primary" value="Ajouter">
<input type="reset" class="btn btn-default" value="Reset">
</div>
</div>
</form>
</div>
require_once'produit.php';
$code_p = isset($_POST['code_p']);
$design =isset($_POST['design']);
$type = isset($_POST['type']);
$qte = isset($_POST['qte']);
$prix = isset($_POST['prix']);
$product = new produit($code_p) ; //create instance (Object) - classe Produit - with __construct()
$product->setAttributs($design,$type,$qte,$prix);
$product->write();
class Produit {
\t \t private $code_p = '';
\t \t private $design;
\t \t private $type;
\t \t private $qte;
\t \t private $prix;
\t \t
\t \t public function __construct($id){
\t \t \t require_once 'connectdb.php';
\t \t \t $this->code_p = $id;
\t \t \t if ($id > 0){
\t \t \t \t $query = "select * from produits where code_p = '$this->code_p'";
\t \t \t \t $result = cmySQL::executQuery($query);
\t \t \t \t while($Row = mysqli_fetch_assoc($result))
\t \t \t {
\t \t \t $this->design = $Row['design'];
\t \t \t $this->type = $Row['type'];
\t \t \t $this->qte = $Row['qte'];
\t \t \t $this->prix = $Row['prix'];
\t \t }
\t \t \t }
\t \t }
\t \t public function setAttributs($design, $type, $qte, $prix){
\t \t \t $this->design = $design;
\t \t \t $this->type = $type;
\t \t \t $this->qte = $qte;
\t \t \t $this->prix = $prix;
\t \t }
\t \t public function setCode_P($code_p){
\t \t \t $this->code_p = $code_p;
\t \t }
\t \t public function getCode_P(){
\t \t \t return $this->code_p;
\t \t }
\t \t public function setDesign($design){
\t \t \t $this->design = $design;
\t \t }
\t \t public function getDesign(){
\t \t \t return $this->design;
\t \t }
\t
public function setType($type){
$this->type=$type;
}
public function getType(){
return $this->type;
\t }
public function setQte($qte){
\t \t $this->qte=$qte;
\t }
\t
public function getQte(){
return $this->qte;
}
public function setPrix($prix){
\t $this->prix=$prix;
}
public function getPrix(){
\t return $this->prix;
}
\t
\t
\t // function pour insertion des donnees dans la table produits //
\t public function write()
\t {
\t \t require_once 'connectdb.php';
\t \t if ($this->code_p == 0){
\t \t \t $sqlQuery = "INSERT INTO produits(code_p,design,type,prix,qte) VALUES('$this->code_p','$this->design','$this->type','$this->prix','$this->qte')";
\t \t }
\t \t else{
\t \t \t $sqlQuery = "UPDATE produits SET `design` = '$this->design', `type` = '$this->type', `qte` = '$this->qte', `prix` = '$this->prix' WHERE code_p='$this->code_p'";
\t \t }
\t \t
\t \t \t \t cmySQL::executQuery($sqlQuery);
\t }
\t public function delete(){
\t \t require_once 'connectdb.php';
\t \t $sqlQuery = "delete from produits where code_p='$this->code_p'";
\t \t //die ($sqlQuery);
\t \t cmySQL::executQuery($sqlQuery);
\t }
'isset()' возвращает логическое значение true/false. это будет ** НИКОГДА не возвращать значение, представленное формой - оно просто скажет вам, если что-то было представлено. –
Добро пожаловать в SO! Возможно, вам стоит подумать о том, чтобы добавить более пояснительный текст о том, в чем заключается ваша проблема, а не просто вставить весь ваш код. Пожалуйста, посмотрите здесь: http://stackoverflow.com/help/how-to-ask – NatureShade
очень жаль, я новый в stackoverflow, спасибо за ссылку – khaledz