HEX
Server: Apache/2.4.37 (CentOS Stream) OpenSSL/1.1.1k
System: Linux ysnet.com.tw 4.18.0-553.5.1.el8.x86_64 #1 SMP Tue May 21 05:46:01 UTC 2024 x86_64
User: test (521)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: /var/www/net/vpnnew.php
<?php
    include "name.php";
    include "mysqllink.php";
    $id = $_POST['id'];
    $address = $_POST['address'];
    $fblink = "select * from $tbname " ;
    $freslut = $dblink->query($fblink ) ;

    if ($freslut) {
        $md=1;
        while ($nb = mysqli_fetch_array($freslut)) {
            $ros[$md]["id"]   = $nb["id"];
            $ros[$md]["name"] = $nb["name"];
            $md++;
        }
    }

    //=== 新增(Replace Into) ===
    if (isset($_POST["new"])) {
        $name    = $_POST["name"];
        $address = $_POST["address"];

        // 使用 REPLACE INTO,並顯式指定欄位
        $sqlstr = "REPLACE INTO $tbname (name, address, ip)
                   VALUES ('$name', '$address', '')";
        $reslut = $dblink->query($sqlstr);

        header("Location:vpnaddresstomysql.php"); 
        exit();

    //=== 修改(Update) ===
    } else if (isset($_POST["change"])) {
        $name    = $_POST["name"];
        $address = $_POST["address"] ;

        for ($i=1; $i<=$md; $i++) {
            if ($ros[$i]['name'] == $name) {
                $id = $ros[$i]['id'];
                $sqlstr = "UPDATE $tbname 
                           SET address = '$address' 
                           WHERE $tbname.id = '$id';" ;
                $reslut = $dblink->query($sqlstr);
                header("Location:vpnaddresstomysql.php?vpn=$id"); 
                exit();
            }
        }

    //=== 刪除(Delete) ===
    } else if (isset($_POST["remove"])) {
        $name = $_POST["name"];
        for ($i=1; $i<=$md; $i++) {
            if ($ros[$i]['name'] == $name) {
                $id = $ros[$i]['id'];
                $sqlstr = "DELETE FROM $tbname 
                           WHERE $tbname.id = '$id'";
                $reslut = $dblink->query($sqlstr);
                header("Location:vpnaddresstomysql.php?add=$id"); 
                exit();
            }
        }

    //=== 返回(Return) ===
    } else if (isset($_POST["return"])) {
        header("Location:vpnaddresstomysql.php"); 
        exit();
    }
?>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>社區列表</title>
        <style>
            form {
                display: inline-block;
                margin-right: 10px; /* 設定按鈕之間的間距 */
            }
        </style>
    </head>
    <h3>編輯資料</h3>
    <body align="center">
        <form action="vpnnew.php" method="post">
            <table border="1" cellspacing="0" cellpadding="4" 
                   bordercolorlight="#3333FF" bordercolordark="#FFFFFF" align="center">
                <tr>
                    <td>社區編號</td>
                    <td>vpn address</td>
                </tr>
                <?php 
                    echo "<tr>";
                    echo "<td><textarea name=\"name\"></textarea></td>" ;
                    echo "<td><textarea name=\"address\"></textarea></td>" ;
                    echo "</tr>";
                ?>
            </table>
            <input type="submit" value="新增" name="new">        
            <input type="submit" value="修改" name="change">        
            <input type="submit" value="刪除" name="remove">
            <input type="submit" value="返回" name="return">
        </form>
    </body>
</html>