在这里有点恼火,尝试了很多东西,但没有任何效果。我想为我的 Magic the Gathering 粉丝网站最终项目制作一个表格,您可以在其中选择复选框以使用字母或根本不填充数据库中的列。
<!Doctype html>
<html>
<head>
</head>
<body>
<?php
if (!empty($_POST)) {
//connect to the database
$mysqli = new mysqli('localhost', 'root', '', 'magic');
//check the connection
if ($mysqli->connect_error) {
die('Connect Error: ' . $mysqli->connect_errno . ': ' . $mysqli->connect_error);
}
//insert the data
$sql = "INSERT INTO decks ( DeckName, Author, CardList ) VALUES ( '{$mysqli->real_escape_string($_POST['DeckName'])}', '{$mysqli->real_escape_string($_POST['Author'])}', '{$mysqli->real_escape_string($_POST['CardList'])}' )";
$insert = $mysqli->query($sql);
//insert the checkbox data
if (isset($_POST['Red'])) {
$sql = "INSERT INTO decks ( Red ) VALUES ( '{$mysqli->real_escape_string('R')}' ) ";
} else {
$sql = "INSERT INTO decks ( Red ) VALUES (' ')";
}
//response from the database
if ($insert) {
echo "Success!";
} else {
die("Error, please try again!");
}
//kill the connection
$mysqli->close();
}
?>
<form method="post" action="">
<input name="DeckName" type="text">
<br>
<br>
<input name="Author" type="text">
<br>
<br>
如果复选框被选中,我希望它在列中放置一个 R,如果没有,则什么都不做。没有任何东西进入专栏。
慕哥6287543