如何使用PDO为表单(选择/选项)捕获数据?
HTML表单:
<form method="post">
<select name="studentactivity">
<option value="Basketball">Basketball</option>
<option value="Football">Football</option>
</select>
</form>
SQL表:
CREATE TABLE `dataset` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`studentactivity` varchar(225) COLLATE utf8_turkish_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci;
答案 0 :(得分:1)
$db = new PDO('mysql:host=localhost;dbname=yourdb;charset=utf8mb4', 'user', 'password');
$stmt = $db->prepare("UPDATE dataset SET studentactivity=:studentActivity WHERE id=:id");
$stmt->bindParam(':studentActivity', $_POST['studentactivity']);
$stmt->bindParam(':id', $_POST['id']);
$stmt->execute();