Diff between 9f94895dfab0f842bd0c93e5eefb8320725ecb75 and 2b6a367db1679ddbf11a4fdece1c82281c49adc5

Changed Files

File Additions Deletions Status
index.php +17 -1 modified
luku.php +28 -7 modified
muokkaa.php +4 -3 modified
style.css +3 -1 modified

Full Patch

diff --git a/index.php b/index.php
index 465eea2..1d99ca4 100755
--- a/index.php
+++ b/index.php
@@ -28,6 +28,7 @@
 				<th>Status</th>
 				<th>Ruokaraha</th>
 				<th>Muuta</th>
+				<th>Muokkaus</th>
 			</tr>
 		<!-- Ota tiedot tiedot kannasta -->
  		<?php
@@ -48,6 +49,21 @@
         <hr>
         <p>&copy; Harjoittelupaikat 2025</p>
         <a href="index.html">Takaisin alkuun</a>
-    </footer>
+	</footer>
+	<script>
+		var inputs = document.querySelectorAll('input'); // get the input element
+		inputs.forEach((input) => {
+			if (input.type == "text")
+			{
+				console.log(input.value);
+				input.addEventListener('input', resizeInput); // bind the "resizeInput" callback on "input" event
+				resizeInput.call(input); // immediately call the function
+			}
+		});
+
+		function resizeInput() {
+			this.style.width = this.value.length + "ch";
+		}
+	</script>
 </body>
 </html>
diff --git a/luku.php b/luku.php
index 721b98b..5686bd1 100755
--- a/luku.php
+++ b/luku.php
@@ -7,8 +7,29 @@ $result = $conn->query($sql); // Aja komento
 // Jos tuloksia
 if ($result->num_rows>0){
 	while($row = $result->fetch_assoc()){
-
-		echo "<tr>";
+		if ($row['id'] === $_GET['id']) // Jos tyyppi on muokattavissa
+		{
+			echo "<tr>";
+			// Muuttaa normaalin tr rivin tableksi
+			echo "<form action='muokkaa.php' method='POST'>";
+			echo "<input type='hidden' id='id' name='id' value={$row['id']}>";
+			echo "<td> <input type='text' name='nimi' id='nimi' value='" . $row["nimi"] . "'> </td>";
+			echo "<td> <input type='text' name='paikka' id='paikka' value='" . $row["paikka"] . "'> </td>";
+			echo "<td> <input type='text' name='ohjaaja' id='ohjaaja' value='" . $row["ohjaaja"] . "'> </td>";
+			echo "<td> <input type='text' name='yhteystiedot' id='yhteystiedot' value='" . $row["yhteystiedot"] . "'> </td>";
+			echo "<td> <input type='date' name='aloitus' id='aloitus' value='" . $row["aloitus"] . "'> </td>";
+			echo "<td> <input type='date' name='lopetus' id='lopetus' value='" . $row["lopetus"] . "'> </td>";
+			echo "<td> <input type='text' name='status' id='status' value='" . $row["status"] . "'> </td>";
+			echo "<td> <input type='text' name='ruokaraha' id='ruokaraha' value='" . $row["ruokaraha"] . "'> </td>";
+			echo "<td> <input type='text' name='muuta' id='muuta' value='" . $row["muuta"] . "'> </td>";
+			echo "<td> <input type='submit' value='Tallenna muutokset' > </td>";
+			echo "</form>";
+			//
+			echo "</tr>";
+		}
+		else // Tyyppiä ei muokata, näytä vaan normaalisti
+		{
+			echo "<tr>";
 			echo "<td>" . $row["nimi"] . "</td>";
 			echo "<td>" . $row["paikka"] . "</td>";
 			echo "<td>" . $row["ohjaaja"] . "</td>";
@@ -22,15 +43,15 @@ if ($result->num_rows>0){
 				"<form action='poista.php' method='POST'>
 				<input type='hidden' id='id' name='id' value={$row['id']}>
 				<input type='submit' value='Poista'>
-				</form>"
-			       	. "</td>";
-			echo "<td>" . // Muokkaa nappi
-				"<form action='muokkaa.php' method='POST'>
+				</form>";
+			echo "" . // Muokkaa nappi
+				"<form action='index.php?id={$row['id']}' method='GET'>
 				<input type='hidden' id='id' name='id' value={$row['id']}>
 				<input type='submit' value='Muokkaa'>
 				</form>"
 			       	. "</td>";
-		echo "</tr>";
+			echo "</tr>";
+		}
 	}
 }
 else{
diff --git a/muokkaa.php b/muokkaa.php
index 1d4fc9d..fde6fed 100644
--- a/muokkaa.php
+++ b/muokkaa.php
@@ -1,16 +1,17 @@
 <?php
+// Yhdistä tietokantaan
 include "connect.php";
 
 $id = $_POST["id"];
-$sql = "UPDATE oppilaat SET nimi='katti' WHERE id={$id}";
-
+$sql = "UPDATE oppilaat SET nimi='{$_POST["nimi"]}' , paikka='{$_POST["paikka"]}' , ohjaaja='{$_POST["ohjaaja"]}' , yhteystiedot='{$_POST["yhteystiedot"]}' , aloitus='{$_POST["aloitus"]}' , lopetus='{$_POST["lopetus"]}' , status='{$_POST["status"]}' , ruokaraha='{$_POST["ruokaraha"]}' , muuta='{$_POST["muuta"]}' WHERE id={$id};";
+echo $sql;
 if ($conn->query($sql) === TRUE) {
   echo "Muutettu onnistuneesti";
 } else {
   echo "Virhe muokkaessa arvoa: " . $conn->error;
 }
-$conn->close();
 
+// Redirect
 $newURL = "index.php";
 header('Location: '.$newURL);
 die();
diff --git a/style.css b/style.css
index b9a3c20..7984b23 100755
--- a/style.css
+++ b/style.css
@@ -24,4 +24,6 @@ aside{
 }
 footer{
     text-align: center;
-}
\ No newline at end of file
+}
+input{
+}