php - 服务器更新脚本中的多个变量

标签 php mysql

您好,我有一个记录详细信息的表格,保存记录后我可以使用链接来更新日记。第一个字段是简单的工作引用,第二个字段基本上是其余所有内容,姓名地址等插入日记中的备注字段中,这是我想出的内容,请给我一些指导。

    <?php
    //record identifier date format 0000-00-00 same as server
    $Dt = $_REQUEST['DT'];
    // text output for appontment
    $A = $_REQUEST['A'];
    $B = $_REQUEST['B'];
    $C = $_REQUEST['C']; 
    $D = $_REQUEST['D'];
    $E = $_REQUEST['E'];
    $F = $_REQUEST['F']; 
    $G = $_REQUEST['G']; 
    $H = $_REQUEST['H'];
    $I = $_REQUEST['I'];
    $J = $_REQUEST['J'];
    $K = $_REQUEST['K']; 
    $L = $_REQUEST['L'];
    $M = $_REQUEST['M'];
    $N = $_REQUEST['N']; 
    // field names to reference
    $APP = $_REQUEST['P'];
    $JD = $_REQUEST['Q'];
    // Field content
    $JN = $_REQUEST['JID'];
    $Desc = $"" . $A . "" . $B . " " . $C . ". " . $D . ", " . $E . " " . $F . " " . $G . " TF " . number_format($H,0, $decimal_point,"") . " " . $I . ", " . $J . " Walls, " . number_format($K,0, $decimal_point,"") . "Beds.  " . $J . " " . $K . " boiler, with " . number_format($L,0, $decimal_point,"") . " radiators. notes " . $M . " observations " . $N . "";
    ?>

    <?php
    $servername = "localhost:3306";
    $username = "xxxdjw";
    $password = "xxxxxx";
    $dbname = "xxxxx";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 

    $sql = "UPDATE masterdiary SET $APP ='$JN', $JD = '$Desc'  WHERE date = '$dt'";

    if ($conn->query($sql) === TRUE) {
        echo "Record updated successfully";
    } else {
        echo "Error updating record: " . $conn->error;
    }

    $conn->close();
    ?>

或者尝试编写触发器会更容易吗?

最佳答案

建议为此使用触发器

下面给出了示例触发器

创建 插入后触发 blog_after_insert ON 博客 对于每一行开始

    IF NEW.deleted THEN
        SET @changetype = 'DELETE';
    ELSE
        SET @changetype = 'NEW';
    END IF;

    INSERT INTO audit (blog_id, changetype) VALUES (NEW.id, @changetype);

END$$

关于php - 服务器更新脚本中的多个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46876577/

相关文章:

php - 存储表单数据的有效方法?

java - 如何正确传递 JDBC url 中的 session 变量?

php - 如何构建PHP模块?

php - MySQL 从具有最新日期的用户中选择最新的不同记录

php - 查询内容最多的前 5 个类别,每个类别返回 5 个内容,并使用 laravel 将 associaled 用户名与内容连接起来

php - 如何使用 php 从 MySQL 数据库打印选定的列表项?

php - 如何使用行数据用 PHP 解析 MySQL 表的结果?

php mysql array - 将数组信息插入mysql

mysql - 帮助调整 my.cnf 中的参数

mysql - SQL:如何更改行顺序位置