Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- //Connection variables
- $dsn = 'mysql:host=localhost;dbname=ZineDB';
- $username = 'root';
- $password = 'elpasso';
- $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Zine DB</title>
- </head>
- <form action="index.php" method="POST">
- <center><h3>Enter the corresponding information about your magazine.</h3></center>
- Magazine Name: <input type="text" name="MagazineName" /> <br/>
- Issue #: <input type="text" name="Issue" /> <br/>
- Release Date: <input type="text" name="Date" /> <br/>
- Special Edition: <input type="radio" name="Special" value="Yes"/>Yes
- <input type="radio" name="Special" value="No"/>No<br/><br/>
- <input type="Submit" value="Go"/>
- <input type="Reset" value="Clear"/><br/><br/>
- </form>
- <body>
- </body>
- </html>
- <?php
- if (!empty ($_POST["MagazineName"]) && !empty ($_POST["Issue"]) && !empty($_POST["Date"]) && isset($_POST['Special']))
- {
- if (filter_var($_POST["Issue"] , FILTER_VALIDATE_INT) === FALSE) {
- die ('You must enter a valid integer in the \'Issue\' field.');}
- $_SESSION["MagazineName"] = $_POST["MagazineName"];
- $_SESSION["Issue"] = $_POST["Issue"];
- $_SESSION["Date"] = $_POST["Date"];
- $_SESSION["Special"] = $_POST["Special"];
- try
- {
- $dbh = new PDO($dsn, $username, $password, $options);
- //Turns ON exception handling
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }catch (PDOException $pdoe) {
- echo $pdoe->getMessage();
- }
- $MagazineName = $_SESSION["MagazineName"];
- $Issue = $_SESSION["Issue"];
- $Date = $_SESSION["Date"];
- $Special_Edition = $_SESSION["Special"];
- try
- {
- $insertMagazine = $dbh->prepare ("INSERT INTO `ZineDB`.`Magazine` (`Magazine_ID`, `Issue`, `Name`, `Release`, `Special`) VALUES (NULL , :issue , :name , :release , :special)");
- $insertMagazine->execute (array(':issue' => $Issue , ':name' => $MagazineName , ':release' => $Date , ':special' => $Special_Edition));
- header ('Location: MagazineInfo.php');
- }catch (PDOException $pdoe2) {
- echo $pdoe2->getMessage();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement