PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/mybookbag/insert.php

https://bitbucket.org/s2223902/mybookbag
PHP | 127 lines | 120 code | 5 blank | 2 comment | 5 complexity | b6e474324f448ef3b17d5e1e6425f5f4 MD5 | raw file
  1. <?php
  2. session_start();
  3. include 'db_connection.php';
  4. include 'functions.php';
  5. if(!isset($_POST)){
  6. $_SESSION["Message"] = "<p>Something went wrong! Try again.</p>";
  7. header("Location:adddoc.php");
  8. }
  9. if(isset($_POST["submitnew"])){ //Treats the given form (other page it is said that users can try and insert new data in two different ways. Refer to that for more explanation.
  10. if(empty($_POST["title"]) || empty($_POST["author"]) || empty($_POST["isbn"])){
  11. $_SESSION["Message"] = "<p>You didn't insert enough data for us to add your new entry!</p>";
  12. header("Location:adddoc.php");
  13. }
  14. else{
  15. $title = $_POST["title"];
  16. $author = $_POST["author"];
  17. $isbn = $_POST["isbn"];
  18. $genre = $_POST["genre"];
  19. $publisher = $_POST["publisher"];
  20. $type = $_POST["type"];
  21. $permission = intval($_POST["permission"]);
  22. $entryid = getid();
  23. }
  24. $queries = array(
  25. 0 => "insert ignore into entry(`entryid`,`type`) values($entryid,'$type')",
  26. 1 => "insert ignore into book(`title`,`entryid`,`isbn`,`type`) values('$title',$entryid,'$isbn','$type')",
  27. 2 => "insert ignore into author(`name`,`birthyear`) values('$author','2010')",
  28. 3 => "insert ignore into author_book(`author`,`entryid`) values('$author',$entryid)",
  29. 4 => "insert ignore into publisher(`name`) values('$publisher')",
  30. 5 => "insert ignore into publisher_book(`publisher`,`entryid`) values('$publisher',$entryid)",
  31. 6 => "insert ignore into genre_book(`genre`,`entryid`) values('$genre',$entryid)",
  32. 7 => "insert into `user_book`(`id`,`entryid`,`permission`) values('{$_SESSION["id"]}',$entryid,$permission)"
  33. );
  34. for($i=0;$i<count($queries);$i++){
  35. $query = mysql_real_escape_string($queries[$i]);
  36. $handle = mysql_query($queries[$i]) or die("Error at $query:".mysql_error());
  37. }
  38. $Msg = "Everything was added neatly!<br/> Go to MyLibrary to check out your new MyBook!";
  39. }
  40. if(isset($_POST["submitpicked"])){
  41. $choice = intval($_POST["choice"]);
  42. $entryid = $_SESSION["rows"][$choice]["entryid"];
  43. $permission = $_POST["permission"];
  44. $id = getid();
  45. $query = "insert into user_book(`id`,`entryid`,`permission`) values({$_SESSION["id"]},$entryid,$permission)";
  46. $query = mysql_real_escape_string($query);
  47. $handle = mysql_query($query) or die("Error at $query:".mysql_error());
  48. $Msg = "Everything was added neatly!<br/> Go to MyLibrary to check out your new MyBook!";
  49. }
  50. ?>
  51. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  52. <html>
  53. <head>
  54. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  55. <link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
  56. <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
  57. <link rel="stylesheet" href="css/formstyles.css" type="text/css" />
  58. <script type="text/javascript" src="js/Placeholders.js"></script>
  59. <script type="text/javascript">
  60. Placeholders.init({
  61. live: true,
  62. hideOnFocus: true});
  63. </script>
  64. <link href="css/toolbar.css" rel="stylesheet" type="text/css" />
  65. <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  66. <title>Add a new MyDoc</title>
  67. </head>
  68. <body>
  69. <?php include ("php/random-bg.php"); ?>
  70. <div id="mainContainer">
  71. <div id="carbonForm2">
  72. <div id="logo2">
  73. <img src="img/logo.png" />
  74. <p>Welcome <b><?php echo $_SESSION['username'];?></b></p>
  75. </div>
  76. <ul id="nav">
  77. <li><a href="page.php">Home</a></li>
  78. <li class="current"><a href="mybooks.php">MyBookBag</a>
  79. <ul>
  80. <li><a href="mybooks.php">My Books</a></li>
  81. <li><a href="myebooks.php">My eBooks</a></li>
  82. <li><a href="myjournals.php">My journals</a></li>
  83. <li><a href="adddoc.php">Add Books</a></li>
  84. </ul>
  85. </li>
  86. <li><a href="friends.php">My Friends</a>
  87. <ul>
  88. <li><a href="friends.php">My Friends</a></li>
  89. <li><a href="messages.php">Messages(<?php echo checkMessages(); ?>)</a></li>
  90. <li><a href="addfriend.php">Add friends</a></li>
  91. <li><a href="requests.php">Friend Requests</a></li>
  92. </ul>
  93. </li>
  94. <li><a href="settings.php">Settings</a>
  95. <ul>
  96. <li><a href="passreset.php">Change Password</a></li>
  97. </ul>
  98. </li>
  99. <li><a href="contact.php">Contact</a></li>
  100. <li><a href="logout.php">Log Out</a></li>
  101. </ul>
  102. <div class="fieldContainer">
  103. <p><h1>Add new MyDoc</h2></p><p>
  104. <?php
  105. //Echo result message.
  106. echo "<h2>$Msg</h2>";
  107. //Delete these variables to avoid weird page refreshing issues
  108. unset($_POST);
  109. unset($_SESSION["rows"]);
  110. ?></p>
  111. </div>
  112. </div>
  113. </div>
  114. </body>
  115. </html>