Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ob_start();
- $servername = "localhost";
- $dbUsername = "";
- $password = "";
- $dbname = "";
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbUsername, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- //echo "Connected successfully";
- } catch (PDOException $e) {
- echo "Connection failed: " . $e->getMessage();
- }
- //create Table
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbUsername, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- // sql to create table
- $sql = "CREATE TABLE IF NOT EXISTS users (
- id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
- username VARCHAR(50) NOT NULL,
- lastname VARCHAR(50) NOT NULL,
- email VARCHAR(90),
- subject VARCHAR(250),
- reg_date TIMESTAMP
- )";
- // use exec() because no results are returned
- $conn->exec($sql);
- //echo "Table users created successfully";
- } catch (PDOException $e) {
- echo $sql . "<br>" . $e->getMessage();
- }
- //Create Table End
- if (isset($_POST['addplant'])) {
- $username = $_POST['username'];
- $lname = $_POST['lname'];
- $email = $_POST['email'];
- $subject = $_POST['subject'];
- //Insert into DB
- try {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbUsername, $password);
- // set the PDO error mode to exception
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "INSERT INTO users (username, lastname, email,subject)
- VALUES ('$username', '$lname', '$email','$subject')";
- // use exec() because no results are returned
- $conn->exec($sql);
- echo "New record created successfully";
- } catch (PDOException $e) {
- echo $sql . "<br>" . $e->getMessage();
- }
- $conn = null;
- //Insert End
- //redirect to another page
- header("Location: productorder.php?username=$username&lname=$lname&email=$email&subject=$subject");
- }
- ?>
- <form name="orderform" id="orderform" method="post" action="">
- <label for="fname"><strong>First Name</strong></label>
- <input type="text" id="fname" name="username" placeholder="Your name..">
- <label for="lname"><b>Last Name</b></label>
- <input type="text" id="lname" name="lname" placeholder="Your last name..">
- <label for="email"><b>Email address</b></label>
- <input type="text" id="email" name="email" placeholder="Your Email address">
- <label for="subject"><b>Comments and Questions</b></label>
- <textarea id="subject" name="subject" placeholder="Contact us..." style="height:200px"></textarea>
- <input type="submit" name="addplant" value="Send my order">
- <input type="reset" class="reset" value="Clear Form">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement