首页 > 解决方案 > php, Record Fetch from two tables

问题描述

we have two tables name "students" AND vouchers. we create the voucher of the fee and display voucher, and we also want to display the roll no of that particular student which was we create voucher, but we can't get the roll any of student table ... we got error,enter image description here I've added the code below

      <?php if(isset($_GET['session_id'])):?>
        <?php $student_session= $_GET['session_id'];?>
        <?php 
        $stu = "select *  from students where 
        session_id='$student_session'";

                $run_stu = mysqli_query($con,$stu);
                while($row = mysqli_fetch_array($run_stu)){
                $stu_id = $row['student_id'];
                $stu_roll = $row['roll_no'];
                $stu_name= $row['s_name'];
            ?>

                <?php

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

    $student_roll = $_GET['roll_no'];

    $student_session_post = $_GET['session_id'];
    $fee_date = $_POST['fee_date'];
    $adm_fee = $_POST['adm_fee'];
    $reg_fee = $_POST['reg_fee'];
    $tution_fee = $_POST['tution_fee'];
    $lab_fund = $_POST['lab_fund'];
    $misc_dues = $_POST['misc_fund'];
    $others = $_POST['others'];
    $total_amount = $_POST['total_amount'];
    $due_date = $_POST['due_date'];
    $remarks = $_POST['remarks'];



    $query = "Insert INTO vouchers(session_id,roll_no,fee_month,adm_fee,reg_fee,tution_fee,lab_fund,misc_dues,other_dues,total_amount,due_date,remarks)
            VALUES('$student_session_post','$student_roll','$fee_date','$adm_fee','$reg_fee','$tution_fee','$lab_fund','$misc_dues','$others','$total_amount','$due_date','$remarks')";
                    if(mysqli_query($con,$query)){

                //echo "<script>alert('Run')</script>";

    }else{
        echo"query failed";
        }
    }

?>

标签: phpsqlmysqli

解决方案


try with this

<?php  if(isset($_POST['many_voucher'])){

    $student_roll = $stu_roll;
}
  ?>

推荐阅读