Advertisement
Guest User

updatecuaca

a guest
Oct 21st, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.39 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5.  
  6. // Create connection
  7. $conn = mysqli_connect($servername, $username, $password);
  8.  
  9. // Check connection
  10. if (!$conn) {
  11.     die("Connection failed: " . mysqli_connect_error());
  12. }
  13. // echo "Connected successfully";
  14.     mysqli_select_db($conn, 'dinkesmalang');
  15.     // mysqli_select_db('dinkesmalang', $conn);
  16.     $sql = "SELECT * FROM cuaca ORDER BY id ASC";
  17.     $mydata = mysqli_query($conn, $sql);
  18.     $count= mysqli_num_rows($mydata);
  19. ?>
  20.  
  21. <!DOCTYPE html>
  22. <html>
  23. <head>
  24.     <title>Update Cuaca</title>
  25.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  26. </head>
  27. <body>
  28.         <form action ='update.php' method=post>
  29.             <table class="table table-responsive">
  30.                 <thead>
  31.                     <tr>
  32.                         <th>Nomor</th>
  33.                         <th>Bulan</th>
  34.                         <th>Tahun</th>
  35.                         <th>Suhu</th>
  36.                         <th>Curah Hujan</th>
  37.                         <th>Kelembaban</th>
  38.                     </tr>
  39.                 </thead>
  40.                 <tbody>
  41.                 <?php
  42.                     while ($row = mysqli_fetch_array($mydata)) {
  43.                         $id = $row['id'];
  44.                         $bulan = $row['bulan'];
  45.                         $tahun = $row['tahun'];
  46.                         $suhu = $row['suhu'];
  47.                         $curah = $row['curahhujan'];
  48.                         $kelembaban = $row['kelembaban'];
  49.                         echo "<tr>";
  50.                         echo "<td align=center>" .$row['id']. "</td>";
  51.                         echo "<td>" . "<input type=number class='form-control' name=bulan value=".$row['bulan']."></td>";
  52.                         echo "<td>" . "<input type=number class='form-control' name=tahun value=".$row['tahun']."></td>";
  53.                         echo "<td>" . "<input type=number class='form-control' name=suhu value=".$row['suhu']."></td>";
  54.                         echo "<td>" . "<input type=number class='form-control' name=curah value=".$row['curahhujan']."></td>";
  55.                         echo "<td>" . "<input type=number class='form-control' name=kelembaban value=".$row['kelembaban']."></td>";
  56.                         echo "</tr>";
  57.                     }
  58.                  ?>
  59.                 </tbody>
  60.             </table>
  61.                         <input type=submit name=submit class='btn btn-primary' value=submit>
  62.         </form>
  63.  
  64.         <?php
  65.         // Check if button name "Submit" is active, do this
  66.             if($Submit){
  67.                     $sql1="UPDATE cuaca SET bulan='$bulan[$i]', tahun='$tahun[$i]', suhu='$suhu[$i]', curahhujan='$curah[$i]', kelembaban='$kelembaban[$i]' WHERE id='$id[$i]'";
  68.                     $result1=mysqli_query($sql1);
  69.             }
  70.         }
  71.  
  72.             if($result1){
  73.                 header("location:updatecuaca2.php");
  74.             }
  75.                 mysqli_close();
  76.         ?>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement