简体   繁体   English

PHP / SQL:我的表单不会将数据发送到数据库中

[英]PHP/SQL: My form won't send data into the database

I am in the process of building this form that lets you type some product details that will go into the SQL database. 我正在构建此表单,可以让您键入一些将进入SQL数据库的产品详细信息。

Right now i am having a problem with PHP logging in details into my SQL database. 现在,我在使用PHP将详细信息登录到SQL数据库时遇到问题。 It doesnt seem to be able to recognize my form. 它似乎无法识别我的表格。

It doesn't make sense because it seems that I have not made any mistakes in my code. 这没有任何意义,因为似乎我的代码没有犯任何错误。 I know the connection to my database is working, but I can not see what is wrong in my code. 我知道与数据库的连接正在工作,但是我看不到代码有什么问题。

Here is the code: 这是代码:

<html>

<?php

ob_start();

$db['db_host'] = "localhost";
$db['db_user'] = "root";
$db['db_pass'] = "root";
$db['db_name'] = "Stockage";

foreach($db as $key => $value){
define(strtoupper($key), $value);
}

$connection = mysqli_connect(DB_HOST, DB_USER,DB_PASS,DB_NAME);



$query = "SET NAMES utf8";
mysqli_query($connection,$query);

if(!$connection){
    echo "Error";
}

?>

<?php 

if(isset($_POST['create_article'])){
    $identifiant = $_POST['identifiant'];
    $designation = $_POST['designation'];
    $prix = $_POST['prix'];
    $quantite = $_POST['quantite'];
    $details = $_POST['details'];

    $query = "INSERT INTO produit(id, Designation, Prix, QuantiteEnStock, Details) ";

    $query .= "VALUES('{$identifiant}', '{$designation}', '{$prix}', '{$quantite}', '$details') ";

    $result=@mysqli_query($connection,$query) or die('probléme ') ;


}

if(!isset($_POST['create_article'])){
    $var = "it's not working";
}

?>

<div class="container">  
  <form id="contact" action="" method="post">
    <h3>Create Product</h3>
    <h3><?php echo $var ?></h3>
    <fieldset>
      <input placeholder="Identifiant" name="identifiant" type="text" tabindex="1" required autofocus>
    </fieldset>
    <fieldset>
      <input placeholder="Designation" name="designation" type="text" tabindex="2" required>
    </fieldset>
    <fieldset>
      <input placeholder="Prix" name="prix" type="tel" tabindex="3" required>
    </fieldset>
    <fieldset>
      <input placeholder="Quantite" name="quantite" type="tel" tabindex="4" required>
    </fieldset>
    <fieldset>
      <textarea placeholder="Details" name="details" tabindex="5" required></textarea>
    </fieldset>
    <fieldset>
      <button  type="submit" id="contact-submit" name="create_article" data-submit="...Sending">Submit</button>
    </fieldset>
  </form>
</div>

What am I doing wrong ? 我究竟做错了什么 ? All answers are appreciated 所有答案表示赞赏

Try setting the action of the form to your page.php and in the Values exclude the curly braces and just house the values in ''. 尝试将表单的操作设置为page.php,然后在“值”中排除花括号,仅将值放在''中。 For example '$prix'. 例如“ $ prix”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM