dongzhang1864 2019-05-11 23:05
浏览 59

在不同的表中更新相同的记录

i have two tables:

table 1 = userfiles table 2 = uploaded

Both tables have multiple columns but have one same column: Title ('ID's are different)

if i update the value of one userfiles.Title it should also update the value of the same uploaded.Title.

if(isset($_POST["btnSubmit"])){
    $id = $_GET['id'];
    $titlefield = $_REQUEST['titlefield'];

    $Title = 'Title';


    $errors = array();


    $conn = mysqli_connect("localhost","root","12345","phpfiles");  

    $query = "UPDATE userfiles, uploaded
                SET userfiles.$Title='$titlefield',
                    uploaded.$Title='$titlefield'
                WHERE
                    userfiles.ID = '$id'
                    uploaded.title='$titlefield'";

    $update2 = mysqli_query($conn, $query);

    mysqli_close($conn);

    $count = count($errors);

    if($count != 0){
        foreach($errors as $error){
            echo $error."<br/>";
        }
    }       
}

if i update (through php web form) userfiles.title(aaaaa) to 'ddddd' it should also update uploaded.title(aaaaa) to (ddddd)

but nothing gets updated

  • 写回答

2条回答 默认 最新

  • doubao6681 2019-05-11 23:32
    关注

    Run first update

    $query = "UPDATE userfiles
                SET userfiles.$Title='$titlefield'
                WHERE
                    userfiles.ID = '$id'";
    $update2 = mysqli_query($conn, $query);
    

    Run second update

    $query = "UPDATE uploaded
                SET uploaded.$Title='$titlefield'
                WHERE
                    uploaded.title='$titlefield'";
    $update2 = mysqli_query($conn, $query);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序