-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
$v) {
unset ($process[$key][$k]);
if (is_array($v)) {
$process[$key][stripcslashes($k)] = $v;
$process[] = &$process[$key][stripcslashes($k)];
}
else {
$process[$key][stripcslashes($k)] = stripcslashes($v);
}
}
}
unset($process);
}
if (isset($_GET['addchampion'])) {
include 'championform.html.php';
exit();
}
if (isset($_GET['addplayer'])) {
include 'playerform.html.php';
exit();
}
//Connection code
try{
$pdo = new PDO('mysql:host=localhost;dbname=project1', 'project1user', 'mypassword');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch (PDOException $e)
{
$output = 'Unable to connect to the database server.' . $e->getMessage();
include 'output.html.php';
exit();
}
/\* $output = 'project1 database connection established.';
include 'output.html.php'; */
/\* First table being made
try {
$sql = 'CREATE TABLE players (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
firstname TEXT NOT NULL,
position TEXT NOT NULL
) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB';
$pdo->exec($sql);
}
catch (PDOException $e)
{
$error = 'Error creating players table: .' . $e->getMessage();
include 'error.html.php';
exit();
}
$output = 'players table successfully created!';
include 'output.html.php';
//Second table being made
try {
$sql = 'CREATE TABLE champions (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name TEXT NOT NULL,
type TEXT NOT NULL
) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB';
$pdo->exec($sql);
}
catch (PDOException $e)
{
$error = 'Error creating champions table: .' . $e->getMessage();
include 'error.html.php';
exit();
}
$output = 'champions table successfully created!';
include 'output.html.php'; */
//-------------------------------PLAYERS----------------------------------------
if (isset($_POST['firstname'])) {
try {
$sql = 'INSERT INTO players SET
firstname = :firstname,
position = :position';
$s = $pdo->prepare($sql);
$s->bindValue(':firstname', $_POST['firstname']);
$s->bindValue(':position', $_POST['position']);
$s->execute();
```
}
catch (PDOException $e) {
$error = 'Error adding submitted player: ' . $e->getMessage();
include 'error.html.php';
exit();
}
```
}
try {
$sql = 'SELECT id, firstname, position FROM players';
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching player: .' . $e->getMessage();
include 'error.html.php';
exit();
}
while($row = $result->fetch())
{
$player[] = array('id' => $row['id'], 'name' => $row['firstname'], 'role' => $row['position']);
}
include 'players.html.php';
//----------------------------------------CHAMPIONS-----------------------------------------------
// Form for adding a champion!
if (isset($_POST['name'])) {
try {
$sql = 'INSERT INTO champions SET
name = :name,
type = :type';
$s = $pdo->prepare($sql);
$s->bindValue(':name', $_POST['name']);
$s->bindValue(':type', $_POST['type']);
$s->execute();
}
catch (PDOException $e) {
$error = 'Error adding submitted champion name: ' . $e->getMessage();
include 'error.html.php';
exit();
}
}
try {
$sql = 'SELECT id, name, type FROM champions';
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching champion name: .' . $e->getMessage();
include 'error.html.php';
exit();
}
while($row = $result->fetch())
{
$champion[] = array('id' => $row['id'], 'namechamp' => $row['name'], 'role' => $row['type']);
}
include 'champions.html.php';
?>
Metadata
Metadata
Assignees
Labels
No labels