PAW tugas 2

mail@pastecode.io avatar
unknown
php
3 years ago
6.1 kB
1
Indexable
Never
<?php
$sukses = "";
 $host = "sql104.epizy.com";
 $user = "epiz_26876316";
 $pwd = "adminakuonline";
 $db = "epiz_26876316_db_tgs22";
 try
 {
     $kon = new PDO( "mysql:host=$host;dbname=$db", $user, $pwd);
     $kon->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
 }
 catch(Exception $e)
 {
     die(var_dump($e));
 }
if(!empty($_POST))
{
    try
    {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $date = date("Y-m-d");
        $sql_insert = "INSERT INTO registration_tbl (name, email, date) 
                        VALUES (?,?,?)";
        $stmt = $kon->prepare($sql_insert);
        $stmt->bindValue(1, $name);
        $stmt->bindValue(2, $email);
        $stmt->bindValue(3, $date);
        $stmt->execute();
    }
        catch(Exception $e)
        {
            die(var_dump($e));
        }
        $sukses ='<div class="alert alert-success col-md-6 offset-md-3 text-center" role="alert">
                <h3>Congratulation, You\'re Registered!</h3>
              </div>';
}
$sql_select = "SELECT * FROM registration_tbl";
 $stmt = $kon->query($sql_select);
 $registrants = $stmt->fetchAll(); 

 ?>

<html>
 <head>
 <Title>FORM REGISTRASI </Title>

 <!-- Including Bootstrap Files -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.0/font/bootstrap-icons.css">
  <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
  <!-- Including Fontawesome Files -->
  <script src="https://kit.fontawesome.com/ee522268d9.js" crossorigin="anonymous"></script>

 </head>
 <body style="background-image: url('bg.jpg')"> 
  <!-- Title Bar -->
  <nav class="navbar navbar-light bg-light">
    <span class="navbar-brand mb-0 h1 mx-auto">TUGAS PEMROGRAMAN APLIKASI WEB</span>
  </nav>
<br>
  <?php echo $sukses; ?>

<div class="col-md-12 mb-4"> 
  <div class="row">
    <div class="col-md-3">
      <div class="card p-4 text-center mt-4 bg-light">
        <img src="fotosiam.jpg" alt="DEFRI" class="rounded-circle" style="width: 100%"><hr>
        <h4>Defri Alif Raihan</h4>
        <small>(185150300111027)</small>
        <hr>
        Teknik Komputer <br>
        Fakultas Ilmu Komputer <br><br>
        <h6>UNIVERSITAS BRAWIJAYA</h6><hr>
           <div class="row text-center mx-auto" >
               <i class="fab fa-facebook fa-2x mx-3"></i>
               <i class="fab fa-instagram fa-2x mx-3"></i>
               <i class="fab fa-whatsapp fa-2x mx-3"></i>
           </div>
      </div>
    </div>

    <div class="col-md-4 mt-4">
      <div class="card">
        <div class="card-body">
          <h5 class="card-title">Form Registrasi Webinar</h5><hr>
          <form action="" method="POST">
            <div class="form-group">
              <label for="name">Nama Lengkap</label>
              <input required="" type="text" class="form-control" name="name" id="name">
            </div>
            <div class="form-group">
              <label for="email">Email</label>
              <input required="" type="email" class="form-control" id="email" name="email" aria-describedby="emailSubtext">
              <small id="emailSubtext" class="form-text text-muted">Email akan digunakan untuk mengirimkan e-sertifikat anda.</small>
            </div>
            <div class="form-group form-check">
              <input type="checkbox" class="form-check-input" id="checkboks1" onchange="check_cb()">
              <label class="form-check-label" for="checkboks1"><small>I agree with the term & conditions</small></label>
            </div>
            <button type="submit" name="submit" id="but-submit" disabled="" class="btn btn-primary" >Daftar</button>
          </form>
        </div>
      </div>
    </div>

    <div class="col-md-5 mt-4">
      <div class="card">
       <div class="card-body">
          <h5 class="card-title">Peserta Terdaftar Saat Ini</h5>
          <table class="table">
            <thead>
              <tr>
                <th scope="col">#</th>
                <th scope="col">Nama</th>
                <th scope="col">Email</th>
                <th scope="col">Tanggal Registrasi</th>
              </tr>
            </thead>
            <tbody>
              <?php 
                   $nomer = 1;
                   if(count($registrants) > 0)
                   {
                       foreach($registrants as $registrant)
                       {

                           echo "<tr>
                                  <th scope='row'>".$nomer."</th>
                                  <td>".$registrant['name']."</td>
                                  <td>".$registrant['email']."</td>
                                  <td>".$registrant['date']."</td>
                                </tr>";
                           $nomer = $nomer+1;
                       }
                   }
                   else
                   {
                       echo "<h3>Belum ada peserta yang ter-registrasi.</h3>";
                   }
               ?>
            </tbody>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
 
 </body>
 </html>

 <script type="text/javascript">
  function check_cb(){
    if (document.getElementById('checkboks1').checked == true) {
      document.getElementById('but-submit').disabled = false;
    }else{
      document.getElementById('but-submit').disabled = true;

    }
   }

 </script>