-
Notifications
You must be signed in to change notification settings - Fork 0
/
add.php
56 lines (53 loc) · 1.73 KB
/
add.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
if(!empty($_POST)){
// add the card to the database
$db = new pdo('mysql:dbname=ambility_flashcards;host=localhost', 'ambility_main', '99wcisftw123');
$stmt = $db->prepare('INSERT INTO `flashcards` (`english`, `pinyin`, `hanzi`) VALUES (?,?,?)');
$stmt->execute(array($_POST['english'], $_POST['pinyin'], $_POST['hanzi']));
}
$db = new pdo('mysql:dbname=ambility_flashcards;host=localhost', 'ambility_main', '99wcisftw123');
$stmt = $db->prepare('SELECT * FROM `flashcards`');
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!doctype html>
<html lang="en">
<head>
<title>Add a New Card</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="css/main.css">
<meta charset="utf-8">
</head>
<body>
<form action="add.php" method="post">
<input type="text" name="english" placeholder="English">
<input type="text" name="pinyin" placeholder="Pinyin">
<input type="text" name="hanzi" placeholder="hanzi">
<input type="submit" value="Create Card">
</form>
<table class="table table-striped">
<thead>
<tr>
<th>id</th>
<th>english</th>
<th>pinyin</th>
<th>hanzi</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $row){
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['english']; ?></td>
<td><?php echo $row['pinyin']; ?></td>
<td><?php echo $row['hanzi']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</body>
</html>