ตัวอย่างการสร้าง Form Insert ข้อมูลนักเรียน


Student Form


HTML Code PHP Code

  • 
    <div class="container" style="margin-top: 4% ">
      <div class="col-md-4 col-md-offset-4">
        <div class="panel panel-danger">
          <div class="panel-heading" align="center">Student Form</div>
            <div class="panel-body">
              <form class="form-group" method="POST">
                <div class="form-row">
    
                  <div class="form-group">
                    <label for="inputStudentname" class="col-form-label">Studentname</label>
                    <input type="text" name="Studentname" class="form-control" placeholder="Studentname" required="">
                  </div>
    
                  <div class="form-group">
                    <label for="inputLastname" class="col-form-label">Lastname</label>
                    <input type="text" name="Lastname" class="form-control" placeholder="Lastname" required="">
                  </div>
    
                  <div class="form-group">
                    <label for="inputClassroom" class="col-form-label">Classroom</label>
                      <select class="form-control" name="Classroom" required="">
                        <option value="">Choose</option>
                      </select>
                  </div>
    
                  <div class="form-group">
                    <label for="inputStatus" class="col-form-label">Status</label>
                      <select class="form-control" name="Statusname" required="">
                        <option value="">Choose</option>    
                      </select>
                    </div>
    
                  <center>
                    <button class="btn btn-info btn-sm" name="Input_Student" type="submit">SAVE</button>
                  </center>
              </form>                              
            </div>
        </div>
      </div>
    </div>
                  
                          
  •             
    if (isset($_POST['Input_Student'])) {
      $Studentname = $_POST["Studentname"];
      $Lastname = $_POST["Lastname"];
      $Classroom = $_POST['Classroom'];
      $Statusname = $_POST['Statusname'];
    
      $Student = "INSERT INTO tb_student(Firstname,Lastname,Class,Status) 
      VALUES ('$Studentname','$Lastname','$Classroom','$Statusname')";
      $studentQR = $Connection->query($Student);
        if ($studentQR) {
          echo "<script> alert('---บันทึกข้อมูลสำเร็จ---'); location='Ls_Example_Student.php';</script>";
        }else{
          echo "เกิดข้อผิดพลาดในการเพิ่มข้อมูล".$Connection->erron();
        }
          $Connection->close();
        }