我无法将表单数据提交到 MySQL 数据库
I cant submit my form data to MySQL database
连接正确字段设置正确但无法从 code.After 中找到问题一个小时前它工作正常但在放置更多字段后它会 stuck.Form 正确提交但是xampp 中的字段有 nothing.Please 帮助我提交 data.See 下面的变量,实际上,下面的所有代码。
<?php
$product = "";
$cost = "";
$other = "";
$otherOne = "";
$code = "";
$price = "";
$qty = "";
$kg = "";
$value = "";
$id = 0;
这是我的 config.php 文件代码,它与我的数据库正确连接,因为它无法显示任何 die() 错误。
<?php
//Database Connection
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'waqar';
$connection = mysqli_connect($host, $user,$pass,$db) or die("<h2>Database Connection Failed. Contact Your Administrator</h2>");
?>
//表单提交时
if(isset($_POST['submit'])) {
$product = $_POST['product'];
$cost = $_POST['cost'];
$other = $_POST['other'];
$otherOne = $_POST['otherOne'];
$code = $_POST['code'];
$price = $_POST['price'];
$qty = $_POST['qty'];
$kg = $_POST['kg'];
$value = $_POST['value'];
//Query
$query = "INSERT INTO managment(product, cost, other, otherOne, code, price, value) VALUES ('$product','$cost','$other', '$otherOne', '$code', '$price', '$qty', '$kg', 'value')";
mysqli_query($connection, $query);
header("location: home.php");
}
?>
<?php include("header.php"); ?>
<div class="content">
<br/>
<div class="row">
<div class="col-lg-10 col-md-10 col-sm-2"></div>
<div class="col-lg-10 col-md-10 col-sm-8">
<div class="login-form">
<form method="post">
<div class="row">
<div class="col-lg-6">
<input class="form-control" type="text" name="product" placeholder="Product..."><br>
</div>
<div class="col-lg-6">
<input class="form-control" type="text" name="code" placeholder="Code..."><br>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<input class="form-control" type="text" name="cost" placeholder="Cost..."><br>
</div>
<div class="col-lg-6">
<input class="form-control" type="text" name="price" placeholder="Price..."><br>
</div>
</div>
<input class="form-control" type="text" name="other" placeholder="Other..."><br>
<input class="form-control" type="text" name="otherOne" placeholder="Other..."><br>
<label class="radio-inline">
<input type="radio" name="qty" id="qty" value="qty"> Quantity
</label>
<label class="radio-inline">
<input type="radio" name="kg" id="kg" value="kg"> Kilograms
</label>
<br><br>
<input class="form-control" type="number" step="1.00" name="value" placeholder="Quantity / Kilograms"><br>
<input class="btn btn-primary pull-right" type="submit" name="submit" value="Add Record">
</form>
<br/>
<br/>
</div>
</div>
<div class="col-lg-10 col-md-10 col-sm-2"></div>
</div>
</div>
<?php include("footer.php"); ?>
您缺少值中的 $
$query = "INSERT INTO managment(product, cost, other, otherOne, code, price, value) VALUES ('$product','$cost','$other', '$otherOne', '$code', '$price', '$qty', '$kg', '$value')";
连接正确字段设置正确但无法从 code.After 中找到问题一个小时前它工作正常但在放置更多字段后它会 stuck.Form 正确提交但是xampp 中的字段有 nothing.Please 帮助我提交 data.See 下面的变量,实际上,下面的所有代码。
<?php
$product = "";
$cost = "";
$other = "";
$otherOne = "";
$code = "";
$price = "";
$qty = "";
$kg = "";
$value = "";
$id = 0;
这是我的 config.php 文件代码,它与我的数据库正确连接,因为它无法显示任何 die() 错误。
<?php
//Database Connection
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'waqar';
$connection = mysqli_connect($host, $user,$pass,$db) or die("<h2>Database Connection Failed. Contact Your Administrator</h2>");
?>
//表单提交时
if(isset($_POST['submit'])) {
$product = $_POST['product'];
$cost = $_POST['cost'];
$other = $_POST['other'];
$otherOne = $_POST['otherOne'];
$code = $_POST['code'];
$price = $_POST['price'];
$qty = $_POST['qty'];
$kg = $_POST['kg'];
$value = $_POST['value'];
//Query
$query = "INSERT INTO managment(product, cost, other, otherOne, code, price, value) VALUES ('$product','$cost','$other', '$otherOne', '$code', '$price', '$qty', '$kg', 'value')";
mysqli_query($connection, $query);
header("location: home.php");
}
?>
<?php include("header.php"); ?>
<div class="content">
<br/>
<div class="row">
<div class="col-lg-10 col-md-10 col-sm-2"></div>
<div class="col-lg-10 col-md-10 col-sm-8">
<div class="login-form">
<form method="post">
<div class="row">
<div class="col-lg-6">
<input class="form-control" type="text" name="product" placeholder="Product..."><br>
</div>
<div class="col-lg-6">
<input class="form-control" type="text" name="code" placeholder="Code..."><br>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<input class="form-control" type="text" name="cost" placeholder="Cost..."><br>
</div>
<div class="col-lg-6">
<input class="form-control" type="text" name="price" placeholder="Price..."><br>
</div>
</div>
<input class="form-control" type="text" name="other" placeholder="Other..."><br>
<input class="form-control" type="text" name="otherOne" placeholder="Other..."><br>
<label class="radio-inline">
<input type="radio" name="qty" id="qty" value="qty"> Quantity
</label>
<label class="radio-inline">
<input type="radio" name="kg" id="kg" value="kg"> Kilograms
</label>
<br><br>
<input class="form-control" type="number" step="1.00" name="value" placeholder="Quantity / Kilograms"><br>
<input class="btn btn-primary pull-right" type="submit" name="submit" value="Add Record">
</form>
<br/>
<br/>
</div>
</div>
<div class="col-lg-10 col-md-10 col-sm-2"></div>
</div>
</div>
<?php include("footer.php"); ?>
您缺少值中的 $
$query = "INSERT INTO managment(product, cost, other, otherOne, code, price, value) VALUES ('$product','$cost','$other', '$otherOne', '$code', '$price', '$qty', '$kg', '$value')";