You are on page 1of 2

<?

php

$dbinfo = 'mysql:dbname=mygames;host=localhost';

$user = 'root';

$pass = 'root';

//If you need to change database information, just change values

above.

$db = new PDO($dbinfo, $user, $pass);

$db->exec('SET CHARACTER SET utf8');

require_once 'includes/db.php';

$sql = $db->query('SELECT id, title, release_date, publisher, rating,

system, num_players FROM videogames ORDER BY title ASC');

$results = $sql->fetchAll(PDO::FETCH_OBJ);

<?php foreach($results as $entry): ?>


<tr>
<td><?php echo $entry->title; ?></td>
<td><?php echo $entry->release_date; ?></td>
<td><?php echo $entry->publisher; ?></td>
<td><?php echo $entry->system; ?></td>
<td><?php echo $entry->rating; ?></td>
<td><?php echo $entry->num_players; ?></td>
<td><a href="edit.php?id=<?php echo $entry->id; ?
>">Edit</a> <a href="delete.php?id=<?php echo $entry->id; ?
>">Delete</a></td>
</tr>
<?php endforeach; ?>
$sql = $db->prepare('DELETE FROM games WHERE id = :id');
$sql->bindValue(':id', $_GET['id'], PDO::PARAM_INT);
$sql->execute();

$sql = $db->prepare('UPDATE games SET title = :title, release_date


= :release_date, publisher = :publisher, system = :system, rating
= :rating, num_players = :num_players WHERE id = :id');
$sql->bindValue(':id', $id, PDO::PARAM_INT);
$sql->bindValue(':title', $title, PDO::PARAM_STR);
$sql->bindValue(':release_date', $release_date,
PDO::PARAM_STR);
$sql->bindValue(':publisher', $publisher,
PDO::PARAM_STR);
$sql->bindValue(':system', $system, PDO::PARAM_STR);
$sql->bindValue(':rating', $rating, PDO::PARAM_INT);
$sql->bindValue(':num_players', $num_players,
PDO::PARAM_INT);

You might also like