2016-07-29 6 views
-1

Wie werden Daten für Formular (select/option) mit PDO erfasst?Wie Datenerfassung mit PDO?

HTML-Formular:

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

SQL-Tabelle:

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; 
+1

Können Sie uns zeigen Sie Ihre Versuche, bitte? Es könnte uns helfen, Ihr Problem besser zu verstehen. – Henders

+0

Welchen Code haben Sie geschrieben, um dieses Problem zu lösen? – Henders

+0

PDO ist kein ORM, Sie verwenden reguläres SQL. (Sie sollten die ID in Ihrem HTML verwenden, da Sie sie bereits haben.) –

Antwort

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();