Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <style>
- body {background-color: grey; font-family: arial;}
- h1 {color: black; font-family: arial; font-size: 100%;}
- h2 {color: black; font-family: arial; font-weight: bold; font-size: 80%;}
- h3 {color: black; font-family: arial; font-weight: bold; font-size: 80%;}
- </style>
- <?php
- $db_hostname = "mysql";
- $db_database = "Filler";
- $db_username = "Filler";
- $db_password = "Filler";
- $db_charset = "utf8mb4";
- $dsn = "mysql:host=$db_hostname;dbname=$db_database;charset=$db_charset";
- $opt = array(
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- PDO::ATTR_EMULATE_PREPARES => false
- );
- try {
- $pdo = new PDO($dsn,$db_username,$db_password,$opt);
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (empty($_POST["name"])) {
- $nameErr = "Name is required";
- } else {
- $name = test_input($_POST["name"]);
- }
- if (empty($_POST["email"])) {
- $emailErr = "Email is required";
- } else {
- $email = test_input($_POST["email"]);
- }
- }
- if (isset($_POST['selectDesc'])) {
- $bookD = $_POST['selectDesc'];
- } else {
- $bookD = 1;
- }
- $bookDescQ = $pdo->query("select ID, Description from Books");
- $researcherQ = $pdo->query("select * from Researchers LEFT JOIN bookOwners ON Researchers.ID = bookOwners.researcherID WHERE bookOwners.bookID = ".$bookD);
- $inputName = $_POST['name'];
- $inputEmail = $_POST['email'];
- if(isset($_POST['submit'])){
- $request = "INSERT INTO Requests (name, email)
- VALUES (\"Hello\", \"Hi\")";
- $result = $pdo->query($request);
- }
- $pdo = NULL;
- } catch (PDOException $e) {
- exit("PDO Error: ".$e->getMessage()."<br>");
- }
- ?>
- <head>
- <!--<link rel = "stylesheet" type = "text/css" href = "styles.css"> -->
- <title>Books:</title>
- </head>
- <body>
- <h1>Books</h1>
- <!-- form, select, foreach loop in php to display the topics -->
- <h2>Choose Book<h2>
- <form name="form1" method="post" action="http://cgi.csc.liv.ac.uk/~u5th/training.php">
- <select name="selectDesc" id="selectDesc" onChange="document.form1.submit();"/>
- <?php
- foreach($bookDescQ as $row) {
- if($row["ID"] == $bookD){
- $selected = " selected";
- } else {
- $selected = "";
- }
- echo "<option ".$selected." value = ".$row["ID"].">".$row["Description"]."</option>";
- }
- ?>
- </select>
- <!-- foreach loop to display the times -->
- <h3>Choose Researcher<h3>
- <select name="selectResearcher" id = "selectResearcher">
- <?php
- foreach($researcherQ as $row) {
- echo "<option>".$row["researcherName"]."</option>";
- }
- ?>
- </select>
- </form>
- <!-- form for inoputting data -->
- <p><span class="error"></span></p>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- <input type="text" name="name">
- <br><br>
- <input type="text" name="email">
- <br><br>
- <input type="submit" name="submit" value="Submit">
- <br><br>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement