使用php mysql从数据库中的一个表获取数据值到另一个表,并将其插入

时间:2019-05-07 19:48:20

标签: php html mysql

我想将fidio_id值插入到名为temp_fir_accept_later的表中,这里io_id是一个新字段,因此可以直接将其成功成功输入到数据库表中。但是fid的值是从另一个先前创建的名为fir的表中获取的,因此当我提交两个值时,fid的Error表示为:

"Notice: Undefined variable: fid in C:\wamp\www\myProjectMJb\dashboard\admin_dashboard_menus\fir_accept_later.php on line 17"

那么我该如何解决该问题?下面我显示了我的代码:

fir_accept.php

<?php 
        include("connectioni.php");
        $edit_record = $_GET['edit'];
        $rs=mysqli_query($con,"SELECT * FROM `fir` WHERE fid='$edit_record'");

        while($row=mysqli_fetch_array($rs))
        {

    ?>
<form action="fir_accept_later.php" method="POST">
    FIR id:<br>
    <input type="text" name="fid" value="<?php echo $row['fid']; ?>"  disabled><br>
    Assigned IO id:<br>
    <input type="text" name="io_id" ><br><br>
    <button type="submit" name="submit">Submit</button><br>
</form>

fir_accept_later.php

<?php

include('connectioni.php');
$dbname="crime_management";
$conn=mysqli_connect($servername, $username,$password,$dbname);
mysqli_select_db($conn,$dbname);

if(isset($_POST['submit'])){

        if (isset($_POST['fid'])) 
            { 
                $fid = $_POST['fid'];
            } 
        $io_id = $_POST['io_id'];


$register_query="INSERT INTO `temp_fir_accept_later`(`fid`, `io_id`) VALUES ('$fid','$io_id')";

mysqli_query($conn,$register_query);
if($register_query){
    echo "Data Entered Successfully!";
}
else {
    echo "Failed!!!";
}
}
?>

0 个答案:

没有答案