Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. <?php
  2. ob_start();
  3.  
  4. $servername = "localhost";
  5. $dbUsername = "";
  6. $password = "";
  7. $dbname = "";
  8.  
  9. try {
  10. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbUsername, $password);
  11. // set the PDO error mode to exception
  12. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  13. //echo "Connected successfully";
  14. } catch (PDOException $e) {
  15. echo "Connection failed: " . $e->getMessage();
  16. }
  17.  
  18.  
  19. //create Table
  20. try {
  21. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbUsername, $password);
  22. // set the PDO error mode to exception
  23. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  24.  
  25. // sql to create table
  26. $sql = "CREATE TABLE IF NOT EXISTS users (
  27. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  28. username VARCHAR(50) NOT NULL,
  29. lastname VARCHAR(50) NOT NULL,
  30. email VARCHAR(90),
  31. subject VARCHAR(250),
  32. reg_date TIMESTAMP
  33. )";
  34.  
  35. // use exec() because no results are returned
  36. $conn->exec($sql);
  37. //echo "Table users created successfully";
  38. } catch (PDOException $e) {
  39. echo $sql . "<br>" . $e->getMessage();
  40. }
  41.  
  42.  
  43. //Create Table End
  44.  
  45.  
  46. if (isset($_POST['addplant'])) {
  47. $username = $_POST['username'];
  48. $lname = $_POST['lname'];
  49. $email = $_POST['email'];
  50. $subject = $_POST['subject'];
  51.  
  52.  
  53. //Insert into DB
  54. try {
  55. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbUsername, $password);
  56. // set the PDO error mode to exception
  57. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  58. $sql = "INSERT INTO users (username, lastname, email,subject)
  59. VALUES ('$username', '$lname', '$email','$subject')";
  60. // use exec() because no results are returned
  61. $conn->exec($sql);
  62. echo "New record created successfully";
  63. } catch (PDOException $e) {
  64. echo $sql . "<br>" . $e->getMessage();
  65. }
  66.  
  67. $conn = null;
  68. //Insert End
  69. //redirect to another page
  70. header("Location: productorder.php?username=$username&lname=$lname&email=$email&subject=$subject");
  71.  
  72.  
  73. }
  74. ?>
  75.  
  76.  
  77. <form name="orderform" id="orderform" method="post" action="">
  78. <label for="fname"><strong>First Name</strong></label>
  79. <input type="text" id="fname" name="username" placeholder="Your name..">
  80.  
  81. <label for="lname"><b>Last Name</b></label>
  82. <input type="text" id="lname" name="lname" placeholder="Your last name..">
  83.  
  84. <label for="email"><b>Email address</b></label>
  85. <input type="text" id="email" name="email" placeholder="Your Email address">
  86.  
  87. <label for="subject"><b>Comments and Questions</b></label>
  88. <textarea id="subject" name="subject" placeholder="Contact us..." style="height:200px"></textarea>
  89.  
  90. <input type="submit" name="addplant" value="Send my order">
  91. <input type="reset" class="reset" value="Clear Form">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement