Advertisement
techcws

Assignment 3

Sep 22nd, 2023 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.17 KB | None | 0 0
  1. --------------------index.php-----------
  2. <?php
  3. // Name:
  4. // Aim:
  5. // Date:
  6. // En.No:
  7. // PC No:
  8. ?>
  9. <!DOCTYPE html>
  10. <html>
  11. <body>
  12.     <h2>Login</h2>
  13.     <form method="post" action="backend.php">
  14.         <label>Username:</label>
  15.         <input type="text" name="username" required><br><br>
  16.        
  17.         <label>Password:</label>
  18.         <input type="password" name="password" required><br><br>
  19.        
  20.         <input type="submit" value="Login">
  21.     </form>
  22. </body>
  23. </html>
  24.  
  25.  
  26. ---------------backend.php--------------
  27.  
  28. <?php
  29.  
  30.     $uname = $_POST["username"];
  31.     setcookie("uname", $uname);
  32.     $pass = $_POST["password"];
  33.    
  34.     if (!preg_match('/^[a-zA-Z]+$/', $uname)) {
  35.         echo "Invalid username. Username should contain only characters.";
  36.     }else{
  37.         $true = 1;
  38.     }
  39.     $length = strlen($pass);
  40.     if ($length < 8 || $length > 15) {
  41.         echo "Password should be between 8 and 15 characters.";
  42.     }else{
  43.         $true = $true + 1;
  44.  
  45.     }
  46.    
  47.    
  48.     echo $true;
  49.     if($true == 2){
  50.         echo "Login successful. Welcome, $uname!";
  51.         echo "Click <a href='welcome.php' >Here </a>to go welcome Page";
  52.         header("Location: welcome.php");
  53.     }
  54. ?>
  55.  
  56.  
  57. ----------------------------welcome.php-----------------
  58.  
  59. <!DOCTYPE html>
  60. <html>
  61. <head>
  62.     <title>Welcome to College</title>
  63. </head>
  64. <body>
  65.     <h2>Welcome to College</h2>
  66.     <p>Welcome <?php echo $_COOKIE["uname"]; ?>!</p>
  67.    
  68.    
  69.     <p>Choose an option:</p>
  70.    
  71.     <ul>
  72.         <li><a href="complain_details.php">Complain Details (soon..)</a></li>
  73.         <li><a href="class_details.php">Class Details</a></li>
  74.         <li><a href="student_profile.php">Student Profile  (soon..)</a></li>
  75.     </ul>
  76.  
  77. </body>
  78. </html>
  79.  
  80.  
  81. -----------class_details.php------------
  82.  
  83. <a href="add_class_details.php">Add Class Details</a><br>
  84. <a href="welcome.php">Home</a>
  85. <h2>All Class Name</h2><br>
  86. <?php
  87. $server = "127.0.0.1";
  88. $user = "root";
  89. $pass = "";
  90. $dbname = "e-complain";
  91.  
  92. $con = new mysqli($server,$user,$pass,$dbname);
  93.  
  94. if (!$con) {
  95.     echo "DB Connection Fail check port number or server";
  96. }else{
  97.     $sql = "select * from class_details";
  98.     $result = $con->query($sql);
  99.     while ($class = mysqli_fetch_array($result)) {
  100.         echo $class[1]."<br>";
  101.     }
  102.  
  103. }
  104.  
  105. ?>
  106.  
  107. -----------add_class_details.php
  108. <body>
  109.     <form action="" method="post">
  110.         <lable>Enter Class Name:- </lable>
  111.         <input type="text" name="cName" /><br>
  112.         <input type="submit">
  113.     </form>
  114. </body>
  115. <?php
  116.  
  117. if (isset($_POST['cName'])) {
  118.     $cname = $_POST['cName'];
  119.     $server = "127.0.0.1";
  120.     $user = "root";
  121.     $pass = "";
  122.     $dbname = "e-complain";
  123.  
  124.     $con = new mysqli($server, $user, $pass, $dbname);
  125.  
  126.     if (!$con) {
  127.         echo "DB Connection Fail check port number or server";
  128.     } else {
  129.         $sql = "INSERT INTO class_details(ClassName) VALUES ('$cname')";
  130.         $result = $con->query($sql);
  131.         if ($result) {
  132.             header('Location: class_details.php');
  133.         }else{
  134.             echo "Error:- Something Want Wrong Value can't insert";
  135.         }
  136.         }
  137.     }
  138. ?>
  139.  
  140.  
  141. ------------next soon.----------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement