1 回答

TA貢獻1803條經驗 獲得超6個贊
要使其發揮作用,您將需要數組符號。(或每行 1 個表格)
這是每行 1 個表單元素的解決方案:
<html>
?<head>
? ? <meta charset="utf-8">
? ? <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
? ? <meta name="description" content="$1">
? ? <meta name="viewport" content="width=device-width, initial-scale=1">
? ? <link rel="stylesheet" type="text/css" href="style.css">
? ? <title>test page</title>
</head>
?<body>? ? ? ? ? ? ? ? ?
? ? ?<?php
? ? ? ? $servername = "localhost";
? ? ? ? $username = "root";
? ? ? ? $password = "root";
? ? ? ? $dbname = "root";
? ? ? ? // Create connection
? ? ? ? $conn = new mysqli($servername, $username, $password, $dbname);
? ? ? ? // Check connection
? ? ? ? if ($conn->connect_error) {
? ? ? ? ? ? die("Connection failed: " . $conn->connect_error);
? ? ? ? }
? ? ? ? $sql = "SELECT `id`, `title`, `amount` FROM `expenses` WHERE name='Porcac1x';";
? ? ? ? $result = $conn->query($sql);
? ? ? ? if ($result->num_rows > 0) {
? ? ? ? ? ? // output data of each row
? ? ? ? ? ? while($row = $result->fetch_assoc()) {
? ? ? ? ? ? ? ? echo '<form method="post">';
? ? ? ? ? ? ? ? echo "ID: <input type='text' name='id' value='".$row["id"]."'> Title: <input type='text' name='title' value='".$row["title"]."'> Amount: <input type='text' name='amount' value='".$row["amount"]."'> <button type='submit' name='save'>Save</button><br>";
? ? ? ? ? ? ? ? echo '</form>';
? ? ? ? ? ? }
? ? ? ? } else {
? ? ? ? ? ? echo "0 results";
? ? ? ? }
? ? ? ? if(isset($_POST['save'])){
? ? ? ? ? ? $myID = $_POST["id"];//??? < Issue
? ? ? ? ? ? $myTitle = $_POST["title"];//??? < Issue
? ? ? ? ? ? $myAmount = $_POST["amount"]; //??? < Issue
? ? ? ? ? ? echo $myID;
? ? ? ? ? ? echo $myTitle;
? ? ? ? ? ? echo $myAmount;
? ? ? ? ? ? $sqlUpdate = "UPDATE expenses SET title='$myTitle', amount ='$myAmount' WHERE id='$myID';";
? ? ? ? ? ? echo $sqlUpdate;
? ? ? ? ? ? if ($conn->multi_query($sqlUpdate) === TRUE) {
? ? ? ? ? ? ? ? echo "Record updated successfully";
? ? ? ? ? ? ? ? $risposta= "Record updated successfully";
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? echo "Error updating record: " . $conn->error;
? ? ? ? ? ? ? ? $risposta= "Error updating record: " . $conn->error;
? ? ? ? ? ? }
? ? ? ? ? ? $conn->close();
? ? ? ? }
? ? ? ? ?>
? ? </body>
</html>
- 1 回答
- 0 關注
- 132 瀏覽
添加回答
舉報