为什么 isset 函数不更新我的数据库?
Why isset function doesn't update my database?
我不明白为什么 isset 函数在这里不起作用:
include 'db.php';
if(isset($_POST['Submit'])) {
$name = $_POST['title'];
$text = $_POST['text'];
$category = $_POST['category'];
$insert = mysqli_query($con,
"INSERT INTO `items`(
`title`,
`text`,
`category`
)
VALUES (
'$name',
'$text',
'$category')"
);
if (!$insert) {
echo mysqli_error($con);
} else {
echo "Inserted!";
}
}
<form method="post">
<input type="text" name="title" placeholder="Enter the title..">
<input type="text" name="text" placeholder="Enter the text..">
<input type="text" name="category" placeholder="Enter the category..">
<input type="submit" value="Submit">
</form>
数据库未更新。
没有它,我的代码还可以,但这不是我想要的。
您输入的提交没有名称属性
<input type="submit" value="Submit" name="Submit">
你需要使用name属性,name属性的文本要和isset($_POST['submit'])
匹配
我不明白为什么 isset 函数在这里不起作用:
include 'db.php';
if(isset($_POST['Submit'])) {
$name = $_POST['title'];
$text = $_POST['text'];
$category = $_POST['category'];
$insert = mysqli_query($con,
"INSERT INTO `items`(
`title`,
`text`,
`category`
)
VALUES (
'$name',
'$text',
'$category')"
);
if (!$insert) {
echo mysqli_error($con);
} else {
echo "Inserted!";
}
}
<form method="post">
<input type="text" name="title" placeholder="Enter the title..">
<input type="text" name="text" placeholder="Enter the text..">
<input type="text" name="category" placeholder="Enter the category..">
<input type="submit" value="Submit">
</form>
数据库未更新。 没有它,我的代码还可以,但这不是我想要的。
您输入的提交没有名称属性
<input type="submit" value="Submit" name="Submit">
你需要使用name属性,name属性的文本要和isset($_POST['submit'])
匹配