Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <title>form practice</title>
- </head>
- <body>
- <div class="form2" id="form2" name="form2">
- <form action="php/form2.php" method="post" id="Personalinfo">
- <label for="fname">Name:</label>
- <input type="text" id="fname" name="firstname" placeholder="Client
- Name..">
- <label for="lname">Lastname:</label>
- <input type="text" id="lname" name="lastname" placeholder="Client
- Lastname..">
- <label for="dob">Birthday:</label>
- <input type="text" id="dob" name="dob" placeholder="yyyy/mm/dd..">
- <label for="age">Age:</label>
- <input type="text" id="age" name="age" placeholder="Client Age..">
- <input type="submit" name="submitForm2" value="Submit">
- </form>
- </div>
- </body>
- </html>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "testdb";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- if(isset($_POST['submitForm2'])){
- $firstname = $_POST['firstname'];
- $lastname = $_POST['lastname'];
- $dob = $_POST['dob'];
- $age = $_POST['age'];
- $sql = "INSERT INTO info (firstname, lastname, dob, age)
- VALUES ('{$firstname}', '{$lastname}', '{$dob}', '{$age}')";
- if ($conn->query($sql) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- }else{
- echo "Are you sure you enter a firstname and the name of your html submit
- is submitForm";
- }
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement