【发布时间】:2017-06-11 23:16:26
【问题描述】:
我正在尝试使用带有 php 的 html post 函数将 1 或 0 插入到数据库中,具体取决于用户是否勾选了复选框,但是每当我提交表单时,我都会收到索引错误,无论是否复选框是否选中。我该如何防止这种情况发生?我得到的错误是“注意:未定义的索引:第 15 行 C:\xampp\htdocs\scout\insertbadgeinphp.php 中的冒险挑战奖”
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "scout";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_POST['submit'])) {
if (!$_POST['Adventure Challenge Award'] == null)
{
$aca = "1";
}
else{
$aca = "0";
}
}
$sql = "INSERT INTO insertbadgescout (AdventureChallengeBadge)
VALUES ('$aca');";
if ($conn->multi_query($sql) === TRUE) {
echo "New records inserted successfully");
}
else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Insert badges scouts have</title>
</head>
<body id="body-color">
<div id="badges">
<form method="POST" action="insertbadgeinphp.php">
<input type="checkbox" name="Adventure Challenge Award" value="yes">Adventure Challenge Award<br>
<input id="button" type="submit" name="submit" value="Save Badges">
</form>
</div>
</body>
<p><a href="Homepage.html"> Home </a> </p>
</html>
【问题讨论】:
-
你能告诉我们你的表单代码吗?
-
谢谢,如下所述,不要在名称属性中使用空格。
标签: php html mysql phpmyadmin xampp