mysqli VALUE 部分不接受来自 html 表单的输入
mysqli VALUE portion not taking input from html form
如何将用户输入存储到两个 html 表单值的 Insert VALUES 中?
在脚本的最后一行,VALUES 不存储来自表单
的这些
<?php
error_reporting(0);
require 'connectit.php';
mysqli_query($db, "INSERT INTO bills (bill_name, bill_cost)
VALUES ($_POST['bill_name'], $_POST['bill_cost'])";
?>
// html form
<form action="updatebill.php" method="post">
<input type="text" name="bill_name" placeholder="Bill name"><br>
<input type="text" name="bill_cost" placeholder="Bill cost"><br>
<input type="submit" value="Submit">
</form>
$link = mysqli_connect("localhost", "root", "", "demo");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$bill_name = mysqli_real_escape_string($link, $_POST['bill_name']);
$bill_cost = mysqli_real_escape_string($link, $_POST['bill_cost']);
// attempt insert query execution
$sql = "INSERT INTO bills (bill_name,bill_cost) VALUES ('$bill_name', '$bill_cost ')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
您的 $_POST
值为空,因为您的表单方法未设置为 POST,请使用
<form action="updatebill.php" method="post">
如何将用户输入存储到两个 html 表单值的 Insert VALUES 中? 在脚本的最后一行,VALUES 不存储来自表单
的这些<?php
error_reporting(0);
require 'connectit.php';
mysqli_query($db, "INSERT INTO bills (bill_name, bill_cost)
VALUES ($_POST['bill_name'], $_POST['bill_cost'])";
?>
// html form
<form action="updatebill.php" method="post">
<input type="text" name="bill_name" placeholder="Bill name"><br>
<input type="text" name="bill_cost" placeholder="Bill cost"><br>
<input type="submit" value="Submit">
</form>
$link = mysqli_connect("localhost", "root", "", "demo");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$bill_name = mysqli_real_escape_string($link, $_POST['bill_name']);
$bill_cost = mysqli_real_escape_string($link, $_POST['bill_cost']);
// attempt insert query execution
$sql = "INSERT INTO bills (bill_name,bill_cost) VALUES ('$bill_name', '$bill_cost ')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
您的 $_POST
值为空,因为您的表单方法未设置为 POST,请使用
<form action="updatebill.php" method="post">