服务器更新脚本中有多个变量

时间:2017-10-22 16:35:53

标签: php mysql

您好我有一张表记录了详细信息,然后在保存记录后我可以使用该链接更新日记。一个字段是一个简单的Job引用,第二个基本上是所有其余的,名称地址等插入到日记中的备忘录字段中,这就是我想出的,我可以请一些指导。

    <?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();
    ?>

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

1 个答案:

答案 0 :(得分:0)

建议使用触发器

下面给出的示例触发器

CREATE     插入后的TRIGGER blog_after_insert     在blog     每行开始

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

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

END$$