从另一个表mysql

时间:2017-09-19 04:12:44

标签: php mysql

我有2个表(违规者和官员),并且他们都有列名参考,现在我想要做的就是每当我向其添加一个新值时违规者表,其参考的值应等于官员表中参考的值。我是编程新手,但我怎样才能实现呢?我无法理解我能在互联网上找到的笔记。这就是我向 violator 表添加值的方法:

php

<?php
$user_name = "Demo";
$password = "Demopass";
$server = "localhost";
$db_name = "TMTRO";

$con = mysqli_connect($server, $user_name, $password, $db_name);
if ($con) {

    $Name = $_POST['name'];
    $LName = $_POST['lname'];
    $LNumber = $_POST['lnumber'];
    $Violation = $_POST['violation'];
    $Aplace = $_POST['aplace'];
    $Address = $_POST['address'];
    $PNumber = $_POST['pnumber'];
    $OName = $_POST['oname'];
    $RNumber = $_POST['rnumber'];
    $DTime = $_POST['dtime'];
    $query = "insert into violators (name,lname,lnumber,violation,aplace,address,pnumber,oname,reference,datetime) values ('" . $Name . "','" . $LName . "','" . $LNumber . "','" . $Violation . "','" . $Aplace . "','" . $Address . "','" . $PNumber . "','" . $OName . "','" . $RNumber . "','" . $DTime . "');";
    $result = mysqli_query($con, $query);

    if ($result) {

        $status = 'OK';


    } else {
        $status = 'FAILED';
    }

} else {
    $status = 'FAILED';
}

echo json_encode(array("response" => $status));

mysqli_close($con);

?>

0 个答案:

没有答案