我正在构建此表单,可以让您键入一些将进入SQL数据库的产品详细信息。
现在,PHP在将详细信息登录到我的SQL数据库时遇到问题。它似乎无法识别我的表格。
这没有意义,因为似乎我的代码没有犯任何错误。我知道与数据库的连接正在工作,但是我看不到代码有什么问题。
代码如下:
<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>
我做错了什么?感谢所有答案
答案 0 :(得分:0)
尝试将表单的操作设置为page.php,并在“值”中排除花括号并将值仅包含在''中。例如“ $ prix”。