duanche8554 2018-06-12 11:53
浏览 143

使用php pdo更新查询mysql中的多个表也检查数据库关系

I am trying to update three table of mysql database. i tried two ways but its not happening.The thing is, someone can check my database table and see the relation and then check my query either it works or not My tables are as follows:

projects     | students     | progress
============================================
Pk ProjectID | PK RegNo     | PK ProgressID
ProjectTitle | Name         | FK RegNo
             | FK ProjectID |

I tried different ways to achieve my updation.

$query= "UPDATE progress SET RegNo='$s1_id' 
         WHERE RegNo IN(SELECT RegNo FROM students WHERE ProjectID = '$id'); 

         UPDATE students SET RegNo='$s1_id', Name='$s1_name' 
         WHERE ProjectID = '$id';

         UPDATE projects SET ProjectTitle='$ptitle' 
         WHERE ProjectID='$id';";  

2nd Way

 $query = "UPDATE projects 
           INNER JOIN students ON students.ProjectID = projects.ProjectID
           INNER JOIN progress ON students.RegNo = progress.RegNo
           SET projects.ProjectTitle = '$ptitle',
               students.RegNo = '$s1_id',
               students.Name = '$s1_name'  ,
               progress.RegNo = '$s1_id' 
           WHERE projects.ProjectID = '$id' ";

try
{
    $stmt = $conn->prepare( $query );  
    $result = $stmt->execute();
    $msg = "Record updated";

    header("location:adminhome.php");
} 
catch(PDOException $ex)
{
    $msg = $ex -> getMessage();
} 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 vue3加ant-design-vue无法渲染出页面
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构