簡體   English   中英

我正在為更新功能開發php頁面

[英]I am developing php page for update function

加載頁面時,它會顯示錯誤消息: idnameaddress未定義。 這些變量處於編輯狀態,但是我不明白如何將這些值放在文本“值”中進行編輯,因為這不起作用。 主要代碼是這樣的。***更新代碼也不是更新值,而是顯示您的記錄已更新

    <?php
    include 'server.php';

    if (isset($_GET['edit'])) {
        $id = $_GET['edit'];
        $update = true;
        $record = mysqli_query($con, "SELECT * FROM info WHERE id=$id");

        if (count($record) == 1) {
            $n = mysqli_fetch_array($record);
            $name = $n['name'];
            $address = $n['address'];
        }
    }
    ?>
    <!-- Form -->
    <!DOCTYPE html>
    <html>
        <head>
            <title>CReate, Update</title>
            <link rel="stylesheet" type="text/css" href="style.css">

        </head>
        <body>

            <form method="post" action="php_code.php" >
                <input type="hidden" name="id" value="<?php echo $id; ?>">
                <input type="text" name="name" value="<?php echo $name; ?>">
                <input type="text" name="address" value="<?php echo $address; ?>">

                <div class="input-group">
                    <?php if ($update == true): ?>
                        <button class="btn" type="submit" name="update" >Update</button>
                    <?php else: ?>
                        <button class="btn" type="submit" name="submit" >save</button>
                    <?php endif ?>
                </div>
            </form>
            <!-- Display -->

            <?php
            $i = 1;
            $q = mysqli_query($con, "select*from info");
            while ($f = mysqli_fetch_array($q)) {
                ?>
                <table>
                    <th> sr N0</th>
                    <th> Name</th>
                    <th> address</th>
                    <th> Action</th>
                    <tr>
                        <td>   <?php echo $i; ?>  </td>
                        <td>   <?php echo $f['name']; ?>  </td>
                        <td>   <?php echo $f['address']; ?>  </td>
                        <td><a href="index.php?edit=<?php echo $f['id']; ?>" class="edit_btn" >Edit</a></td>
                    </tr>
                    <?php $i ++;
                }
                ?>
            </table>
        </body>
    </html>



<?php
include 'server.php';
if (isset($_POST['save']))
{
    $name= $_POST['name'];
    $add= $_POST['address'];
    $q = "INSERT into info (name,address) VALUES ('$name', '$add')";
    mysqli_query($con, $q);
    echo "inserted";
}

 if (isset($_POST['update']))
 {
    $uname= $_POST['name'];
    $uaddress= $_POST['address'];
    $q = "UPDATE info set name= '$uname', adress= '$uaddress' WHERE id = $id";
    mysqli_query($con, $q);
    echo "updated";

 }


?>

使

if (count($record) == 1 ) {

if (mysqli_num_rows($record) == 1 ) {

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM