Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- // echo "Connected successfully";
- mysqli_select_db($conn, 'dinkesmalang');
- // mysqli_select_db('dinkesmalang', $conn);
- $sql = "SELECT * FROM cuaca ORDER BY id ASC";
- $mydata = mysqli_query($conn, $sql);
- $count= mysqli_num_rows($mydata);
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Update Cuaca</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
- </head>
- <body>
- <form action ='update.php' method=post>
- <table class="table table-responsive">
- <thead>
- <tr>
- <th>Nomor</th>
- <th>Bulan</th>
- <th>Tahun</th>
- <th>Suhu</th>
- <th>Curah Hujan</th>
- <th>Kelembaban</th>
- </tr>
- </thead>
- <tbody>
- <?php
- while ($row = mysqli_fetch_array($mydata)) {
- $id = $row['id'];
- $bulan = $row['bulan'];
- $tahun = $row['tahun'];
- $suhu = $row['suhu'];
- $curah = $row['curahhujan'];
- $kelembaban = $row['kelembaban'];
- echo "<tr>";
- echo "<td align=center>" .$row['id']. "</td>";
- echo "<td>" . "<input type=number class='form-control' name=bulan value=".$row['bulan']."></td>";
- echo "<td>" . "<input type=number class='form-control' name=tahun value=".$row['tahun']."></td>";
- echo "<td>" . "<input type=number class='form-control' name=suhu value=".$row['suhu']."></td>";
- echo "<td>" . "<input type=number class='form-control' name=curah value=".$row['curahhujan']."></td>";
- echo "<td>" . "<input type=number class='form-control' name=kelembaban value=".$row['kelembaban']."></td>";
- echo "</tr>";
- }
- ?>
- </tbody>
- </table>
- <input type=submit name=submit class='btn btn-primary' value=submit>
- </form>
- <?php
- // Check if button name "Submit" is active, do this
- if($Submit){
- $sql1="UPDATE cuaca SET bulan='$bulan[$i]', tahun='$tahun[$i]', suhu='$suhu[$i]', curahhujan='$curah[$i]', kelembaban='$kelembaban[$i]' WHERE id='$id[$i]'";
- $result1=mysqli_query($sql1);
- }
- }
- if($result1){
- header("location:updatecuaca2.php");
- }
- mysqli_close();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement