我正在开发更新功能的php页面

时间:2018-03-22 08:19:39

标签: php sql-update

加载页面时,显示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";

 }


?>

1 个答案:

答案 0 :(得分:0)

webpack-dev-server --open --config webpack.dev.js

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