<?php require_once 'libcollection.php'; startSession(); $storyGenerated = FALSE; if (isset($_POST['title']) && isset($_POST['hero']) && isset($_POST['villain']) && isset($_POST['story'])) { $title = strip_tags($_POST['title']); if ($title != '') { $storyGenerated = TRUE; $hero = $_POST['hero']; $villain = $_POST['villain']; $story = $_POST['story']; $user = $_SESSION['username']; $lair_list = array('Wolf' => 'Den', 'Witch' => 'Gingerbread-house', 'Giant' => 'Castle'); $lair = $lair_list[$villain]; //select appropriate lair with respect to villain db_connect(); db_add_new_book($user, $title, $story, $hero, $villain, $lair); db_close(); $location = 'storygen.php?title=' . urlencode($title) . '&story=' . urlencode($story) . "&hero=" . urlencode($hero) . '&villain=' . urlencode($villain) . '&lair=' . urlencode($lair) . '&page=0'; header('location: ' . $location); } else { /* $_SESSION['hero'] = $_POST['hero']; $_SESSION['villain'] = $_POST['villain']; $_SESSION['story'] = $_POST['story']; */ } } if ($storyGenerated == FALSE) { header('location: selection.php'); }
<?php require_once 'libcollection.php'; startSession(); $list_of_users = array(array('username' => '*****@*****.**', 'password' => 'abdcdef'), array('username' => '*****@*****.**', 'password' => '1234567'), array('username' => '*****@*****.**', 'password' => 'abc123')); $list_of_books = array(array('username' => '*****@*****.**', 'title' => 'My first story', 'story' => '2', 'hero' => 'Jack', 'villain' => 'Giant', 'lair' => 'Castle'), array('username' => '*****@*****.**', 'title' => 'My second story', 'story' => '3', 'hero' => 'Red Riding Hood', 'villain' => 'Witch', 'lair' => 'Gingerbread-house'), array('username' => '*****@*****.**', 'title' => 'The best story', 'story' => '1', 'hero' => 'Jack', 'villain' => 'Wolf', 'lair' => 'Den')); db_connect(); while (count($list_of_users) != 0) { $user = array_pop($list_of_users); db_add_new_user($user['username'], $user['password']); } while (count($list_of_books) != 0) { $book = array_pop($list_of_books); db_add_new_book($book['username'], $book['title'], $book['story'], $book['hero'], $book['villain'], $book['lair']); } $message .= 'Tables populated successfully'; $_SESSION['message'] = $message; header('location: adminPage.php'); ?>