Advertisement
Guest User

Untitled

a guest
Sep 29th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.56 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.    
  4.     //Connection variables
  5.     $dsn = 'mysql:host=localhost;dbname=ZineDB';
  6.     $username = 'root';
  7.     $password = 'elpasso';
  8.     $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
  9. ?>
  10. <!DOCTYPE html>
  11. <html>
  12.     <head>
  13.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  14.         <title>Zine DB</title>
  15.     </head>
  16.         <form action="index.php" method="POST">
  17.             <center><h3>Enter the corresponding information about your magazine.</h3></center>
  18.             Magazine Name: <input type="text" name="MagazineName" /> <br/>
  19.             Issue #:       <input type="text" name="Issue" /> <br/>
  20.             Release Date:  <input type="text" name="Date" /> <br/>
  21.             Special Edition: <input type="radio" name="Special" value="Yes"/>Yes
  22.                              <input type="radio" name="Special" value="No"/>No<br/><br/>
  23.                            <input type="Submit" value="Go"/>
  24.                            <input type="Reset" value="Clear"/><br/><br/>
  25.         </form>
  26.     <body>
  27.     </body>
  28. </html>
  29.  
  30. <?php
  31.     if (!empty ($_POST["MagazineName"]) && !empty ($_POST["Issue"]) && !empty($_POST["Date"]) && isset($_POST['Special']))
  32.     {
  33.         if (filter_var($_POST["Issue"] , FILTER_VALIDATE_INT) === FALSE) {
  34.                 die ('You must enter a valid integer in the \'Issue\' field.');}    
  35.        
  36.         $_SESSION["MagazineName"] = $_POST["MagazineName"];
  37.         $_SESSION["Issue"] = $_POST["Issue"];
  38.         $_SESSION["Date"] = $_POST["Date"];
  39.         $_SESSION["Special"] = $_POST["Special"];
  40.         try
  41.         {
  42.             $dbh = new PDO($dsn, $username, $password, $options);
  43.             //Turns ON exception handling
  44.             $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  45.         }catch (PDOException $pdoe) {
  46.             echo $pdoe->getMessage();
  47.         }
  48.         $MagazineName = $_SESSION["MagazineName"];
  49.         $Issue = $_SESSION["Issue"];
  50.         $Date = $_SESSION["Date"];
  51.         $Special_Edition = $_SESSION["Special"];
  52.         try
  53.         {
  54.             $insertMagazine = $dbh->prepare ("INSERT INTO `ZineDB`.`Magazine` (`Magazine_ID`, `Issue`, `Name`, `Release`, `Special`) VALUES (NULL , :issue , :name , :release , :special)");
  55.             $insertMagazine->execute (array(':issue' => $Issue , ':name' => $MagazineName , ':release' => $Date , ':special' => $Special_Edition));
  56.             header ('Location: MagazineInfo.php');
  57.         }catch (PDOException $pdoe2) {
  58.             echo $pdoe2->getMessage();
  59.         }
  60.     }
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement