0

How to data is captured for form (select/option) with PDO?

HTML form:

<form method="post">
<select name="studentactivity">
<option value="Basketball">Basketball</option>
<option value="Football">Football</option>
</select>
</form>

SQL table:

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;
3
  • 1
    Could you show us your attempts, please? It might help us better understand your issue.
    – Henders
    Jul 29, 2016 at 11:22
  • What code have you written to try and solve this problem?
    – Henders
    Jul 29, 2016 at 11:26
  • PDO is not an ORM, you use regular SQL. (You should use the id in your HTML since you already have it.) Jul 29, 2016 at 11:30

1 Answer 1

2
    $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();
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.