簡體   English   中英

插入到當前表並更新到另一個表php

[英]insert to a current table and update to another table php

我有兩個表,分別是采訪和個人信息。 我在將值插入數據庫時​​遇到問題。 我需要將txtTest,txtIntervieweddBy,txtRemarksDate,txtComment和txtRemarks的值插入到采訪表中。 該txtRemarksStatus的格式也相同,但它的用途是更新另一個名為personal_info的表中的行。

<?php
    include_once 'php/connection.php';
    $connect = mysqli_connect("localhost", "root", "", "trackingsystemdb");
    $number = count($_POST["txtIntervieweddBy"]);

    if($number > 0)
    {
        for($i=0; $i<$number; $i++)
        {
            if(trim($_POST["txtIntervieweddBy"][$i] != ''))
            {
                $sql = "INSERT INTO interview (applicant_code, interviewed, dateInterviewed, comment, remarks) VALUES('".mysqli_real_escape_string($connect, $_POST["txtTest"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtIntervieweddBy"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtRemarksDate"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtComment"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtRemarks"][$i])."')";

            }
        }
    }

    $id = $_GET['id'];
    $txtRemarksStatus=$_GET['txtRemarksStatus'];
    $sql = "UPDATE personal_info SET status =  '$txtRemarksStatus'          
            WHERE applicant_code = '$id'";

    if (mysqli_multi_query($connect, $sql)) {
    } else {
        echo "Error ".mysqli_error($connect);
    }

    header('Location: addinterview.php?insert=sucess');
    exit();

?>

像這樣使用它:

 include_once 'php/connection.php';
    $connect = mysqli_connect("localhost", "root", "", "trackingsystemdb");
    $number = count($_POST["txtIntervieweddBy"]);

    if($number > 0)
    {
        for($i=0; $i<$number; $i++)
        {
            if(trim($_POST["txtIntervieweddBy"][$i] != ''))
            {
                $sql = "INSERT INTO interview (applicant_code, interviewed, dateInterviewed, comment, remarks) VALUES('".mysqli_real_escape_string($connect, $_POST["txtTest"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtIntervieweddBy"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtRemarksDate"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtComment"][$i])."','".mysqli_real_escape_string($connect, $_POST["txtRemarks"][$i])."')";
mysqli_query($connect, $sql);
            }
        }
    }

    $id = $_GET['id'];
    $txtRemarksStatus=$_GET['txtRemarksStatus'];
    $sql = "UPDATE personal_info SET status =  '$txtRemarksStatus'          
            WHERE applicant_code = '$id'";

    if (mysqli_query($connect, $sql)) {
    } else {
        echo "Error ".mysqli_error($connect);
    }

    header('Location: addinterview.php?insert=sucess');
    exit();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM