Advertisement
HawkeyeHS

Untitled

Oct 28th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.67 KB | None | 0 0
  1. <?php
  2. $insert = false;
  3. if(isset($_POST['name'])){
  4.     // Set connection variables
  5.     $server = "localhost";
  6.     $username = "root";
  7.     $password = "";
  8.  
  9.     // Create a database connection
  10.     $con = mysqli_connect($server, $username, $password);
  11.  
  12.     // Check for connection success
  13.     if(!$con){
  14.         die("connection to this database failed due to" . mysqli_connect_error());
  15.     }
  16.     // echo "Success connecting to the db";
  17.  
  18.     // Collect post variables
  19.     $name = $_POST['name'];
  20.     $gender = $_POST['gender'];
  21.     $age = $_POST['age'];
  22.     $email = $_POST['email'];
  23.     $phone = $_POST['phone'];
  24.     $desc = $_POST['desc'];
  25.     $sql = "INSERT INTO `trip`.`trip` (`sno`,`name`, `age`, `gender`, `email`, `phone`, `other`, `dt`) VALUES (NULL,'$name', '$age', '$gender', '$email', '$phone', '$desc', current_timestamp());";
  26.     // echo $sql;
  27.  
  28.     // Execute the query
  29.     if($con->query($sql) == true){
  30.         // echo "Successfully inserted";
  31.  
  32.         // Flag for successful insertion
  33.         $insert = true;
  34.     }
  35.     else{
  36.         echo "ERROR: $sql <br> $con->error";
  37.     }
  38.  
  39.     // Close the database connection
  40.     $con->close();
  41. }
  42. ?>
  43.  
  44. <!DOCTYPE html>
  45. <html lang="en">
  46. <head>
  47.     <meta charset="UTF-8">
  48.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  49.     <title>Welcome to Travel Form</title>
  50.     <link href="https://fonts.googleapis.com/css?family=Roboto|Sriracha&display=swap" rel="stylesheet">
  51.     <link rel="stylesheet" href="style.css">
  52. </head>
  53. <body>
  54.     <img class="bg" src="bg.jpg" alt="IIT Kharagpur">
  55.     <div class="container">
  56.         <h1>Welcome to IIT Kharagpur US Trip form</h3>
  57.         <p>Enter your details and submit this form to confirm your participation in the trip </p>
  58.         <?php
  59.         if($insert == true){
  60.         echo "<p class='submitMsg'>Thanks for submitting your form. We are happy to see you joining us for the US trip</p>";
  61.         }
  62.     ?>
  63.         <form action="index.php" method="post">
  64.             <input type="text" name="name" id="name" placeholder="Enter your name">
  65.             <input type="text" name="age" id="age" placeholder="Enter your Age">
  66.             <input type="text" name="gender" id="gender" placeholder="Enter your gender">
  67.             <input type="email" name="email" id="email" placeholder="Enter your email">
  68.             <input type="phone" name="phone" id="phone" placeholder="Enter your phone">
  69.             <textarea name="desc" id="desc" cols="30" rows="10" placeholder="Enter any other information here"></textarea>
  70.             <button class="btn">Submit</button>
  71.         </form>
  72.     </div>
  73.     <script src="index.js"></script>
  74.    
  75. </body>
  76. </html>
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement