Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. <html>
  2. <body>
  3. <form action="addchar.php" method="post">
  4. <select name="bookIntroduced">
  5. <option value="1">A Game of Thrones</option>
  6. <option value="2">A Clash of Kings</option>
  7. <option value="3">A Storm of Swords</option>
  8. <option value="4">A Feast for Crows</option>
  9. <option value="5">A Dance with Dragons</option>
  10. </select>
  11. <p>
  12. Page introduced:<br>
  13. <input type="text" name="pageIntroduced" tabindex=1 autofocus>
  14. <br>Title:<br>
  15. <input type="text" name="title" tabindex=2>
  16. <br>First name<br>
  17. <input type="text" name="forename" tabindex=3>
  18. <br>Surname<br>
  19. <input type="text" name="surname" tabindex=4>
  20. <br>Old surname<br>
  21. <input type="text" name="oldSurname" tabindex=5>
  22. <br>Alias or nickname<br>
  23. <input type="text" name="alias" tabindex=6>
  24. <br>Regnal number<br>
  25. <input type="text" name="regnalNumber" tabindex=7>
  26. <br>
  27. <input type="submit" value="Add character" tabindex=8>
  28. </p>
  29. </form>
  30. <?php
  31. // Displays the message returned from the PHP script.
  32. if ($_GET['msg']) {
  33. echo "<br>".$_GET['msg'];
  34. }
  35.  
  36. ?>
  37. </body>
  38.  
  39. <?php
  40.  
  41. if ($_POST) {
  42. // Configuration.
  43. $username = "root";
  44. $password = "root";
  45. $hostname = "localhost";
  46. $dbname = "asoiaf";
  47. $tablename = "charlist";
  48.  
  49. // Opens a connection to the database.
  50. try {
  51. $conn = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
  52. // I don't know what this does; a
  53. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  54. } catch(PDOException $e) {
  55. echo $e->getmessage();
  56. }
  57.  
  58. // Gets the next available primary key from the table.
  59. $qry = $conn->query("SELECT Auto_Increment FROM information_schema.tables WHERE table_name='$tablename'");
  60. // Fetches the result of the query, stores it in $result.
  61. $result = $qry->fetch();
  62. // Puts the resulting primary key into $id.
  63. $id = $result['Auto_Increment'];
  64. // Fetches all the other information from the form.
  65. $bookIntroduced = $_POST['bookIntroduced'];
  66. $pageIntroduced = $_POST['pageIntroduced'];
  67. $forename = $_POST['forename'];
  68. $surname = $_POST['surname'];
  69. $oldSurname = $_POST['oldSurname'];
  70. $alias = $_POST['alias'];
  71. $title = $_POST['title'];
  72. $regnalNumber = $_POST['regnalNumber'];
  73.  
  74. // Queries the table to see if a record exists with the same forename and surname values.
  75. $qry = $conn->query("SELECT forename, surname FROM charlist WHERE forename='$forename' AND surname='$surname'");
  76. $result = $qry->fetch();
  77. // If a record with the same forename/surname exists, the entry is a duplicate entry and should be disallowed.
  78. if ($result[0]==$forename && $result[1]=$surname) {
  79. // Return to the original page reporting a duplicate error.
  80. header('Location: asoiaf.php?msg=duplicate error');
  81. } else {
  82. // Prepare the SQL statement.
  83. $sql = "INSERT INTO $tablename (id, bookIntroduced, pageIntroduced, forename, surname, oldSurname, alias, title, regnalNumber)
  84. VALUES (:id, :bookIntroduced, :pageIntroduced, :forename, :surname, :oldSurname, :alias, :title, :regnalNumber)";
  85. $q = $conn -> prepare($sql);
  86. // Executes the SQL.
  87. $q -> execute(array(':id' => $id, ':bookIntroduced' => $bookIntroduced, ':pageIntroduced' => $pageIntroduced, ':forename' => $forename, ':surname' => $surname, ':oldSurname' => $oldSurname, ':alias' => $alias, ':title' => $title, ':regnalNumber' => $regnalNumber));
  88.  
  89. // Closes the PDO connection.
  90. $conn = null;
  91.  
  92. // Returns to the original HTML page.
  93. header('Location: asoiaf.php?msg=success');
  94. }
  95. }
  96. ?>
  97.  
  98. http://localhost/asoiaf.php?msg=%3Cscript%3Ealert(%22bad%22)%3C/script%3E
  99.  
  100. <script>alert("bad");</script>
  101.  
  102. echo $e->getmessage();
  103.  
  104. // I don't know what this does; a
  105. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement