我希望管理员添加学生费用

问题描述 投票:0回答:0

我希望管理员添加学生费用我使用文本框插入学生姓名 当我确定费用类型时,我使用了多动态列表,费用出现 我使用随机函数作为收据编号。 我有 4 个页面(indexmysqli.php、fetchmysqli.php、insertmysqli.php、 连接mysqli.php)

我有三张桌子

    Table structure for table `st_info`
    --
    CREATE TABLE `st_info` (
    `st_id` int(12) NOT NULL AUTO_INCREMENT,
    `st_fullname` varchar(100) NOT NULL,
    `st_username` varchar(30) NOT NULL,
    `st_password` varchar(100) NOT NULL,
    `religion` varchar(50) NOT NULL,
    `old_school` varchar(100) NOT NULL,
    `status` varchar(300) NOT NULL,
    `st_grade` int(5) NOT NULL,
    `roll_no` int(5) NOT NULL,
    `st_dob` varchar(20) NOT NULL,
    `st_address` varchar(100) NOT NULL,
    `home_no` int(100) NOT NULL,
    `st_gender` varchar(12) NOT NULL,
    `st_father` varchar(100) NOT NULL,
    `st_mother` varchar(100) NOT NULL,
    `st_parents_contact` varchar(15) NOT NULL,
    `father_job` varchar(100) NOT NULL,
    PRIMARY KEY (`st_id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=latin1;
    -- Table structure for table `sch_tran`
    --
    CREATE TABLE `sch_tran` (
    `tran_id` int(11) NOT NULL AUTO_INCREMENT,
    `Reciept` varchar(100) NOT NULL,
    `st_fullname` varchar(100) NOT NULL,
    `fee` float NOT NULL,
    `fee_type` varchar(100) NOT NULL,
    `pay_mode` varchar(20) NOT NULL,
    `current_day` date NOT NULL,
    PRIMARY KEY (`tran_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    Table structure for table `sch_fee`
    CREATE TABLE `sch_fee` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `grade` int(11) NOT NULL,
    `fee_type` varchar(200) NOT NULL,
    `fee` float NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1;

我不知道哪里出了问题,但它不起作用,请帮助我并纠正我的代码

    My pages

    indexmysqli.php
    
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);

    include('connectionmysqli.php');
    $RCP= generateRandomString($connection);
    function generateRandomString($connection) {
    $length =5;
    $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
    $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    $RCP='RC'.$randomString;
    $result=mysqli_query($connection,"select * from 
    sch_tran where Reciept='$RCP'");
    //  var_dump($result);
    if((mysqli_num_rows($result))!=null){
    generateRandomString($connection);
    }
    return $RCP;
    } 

    $fee_type = '';

    $query = $connection->query("SELECT fee_type FROM sch_fee ");
    $result = $query->fetch_all(MYSQLI_ASSOC);

    foreach($result as $row)
    {$fee_type = '<option   value="'.$row["fee_type"].'">'
    .$row["fee_type"].'</option>';
    }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <title> Multi Select Box Data using Jquery Ajax PHP</title>
    <script src="https://ajax.googleapis.com/ajax/libs
    /jquery/3.1.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.
    bootstrapcdn.com/bootstrap/3.3.6/
    css/bootstrap.min.css"    />
    <script src="https://maxcdn.bootstrapcdn.com
    /bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="jquery.lwMultiSelect.js"></script>
    <link rel="stylesheet" href="jquery.lwMultiSelect.css" />
    </head>
    <body>
    <br /><br />
    <div class="container" style="width:600px;">
    <h2 align="center">Insert Dynamic Multi Select Box Data 
    using Jquery Ajax PHP</h2><br /><br />
    <form  action="indexmysqli.php" method="post" id="insert_data">
    <label>Fullname</label>
    <input type="text" name="st_fullname" id="st_fullname" 
    class="form-control action">
    <br />
    <select name="fee_type" id="fee_type" class="form-control action">
    <option value="">Select fee_type</option>
    <?php echo $fee_type; ?>
    </select>
    <br />
    <select name="fee" id="fee" class="form-control action">
    <option value="">Select fee</option>
    </select>
    <br />
    <label>Pay Mode</label>
    <select name="pay_mode" id="pay_mode" class="form-control action">
    <option value="">select</option>
    <option value="Cash">CASH</option>
    <option value="Cheque">CHEQUE</option>
    </select>
    <br>
    Reciept Number: <input type="text" value="<?php echo($RCP); ?>" 
    name="Reciept" class="form-control  action">
    <input type="submit" name="insert" id="action" 
    class="btn btn-info" value="Insert" />
    </form>
    </div>
    </body>
    </html>

    <script>
    $(document).ready(function(){
    $('.action').change(function(){
    if($(this).val() != '')
    {
    var action = $(this).attr("id");
    var query = $(this).val();
    var result = '';
    if(action == 'fee_type')
    {
    result = 'fee';
    }
    $.ajax({
    url:'fetchmysqli.php',
    method:"POST",
    data:{action:action, query:query},
    success:function(data)
    {
    $('#'+result).html(data);
    }
    })
    }
    });

    $('#insert_data').on('submit', function(event){
    event.preventDefault();
    if($('#fee_type').val() == '')
    {
    alert("Please Select fee_type");
    return false;
    }
    else if($('#fee').val() == '')
    {
    alert("Please Select fee");
    return false;
    }
    else if($('#st_fullname').val() == '')
    {
    alert("Please Select st_fullname");
    return false;
    }
    else if($('#Reciept').val() == '')
    {
    alert("Please Select Reciept");
    return false;
    }
    else if($('#pay_mode').val() == '')
    {
    alert("Please Select pay mode");
    return false;

    }
    else
    {

    $('#action').attr('disabled', 'disabled');
    var form_data = $(this).serialize();
    $.ajax({
    url:"insertmysqli.php",
    method:"POST",
    data:form_data,
    success:function(data)
    {
    $('#action').attr("disabled", "disabled");
    if(data == 'done')
    {

    $('#insert_data')[0].reset();
    alert('Data Inserted');
    }
    }
    });
    }
    });

    });
    </script>


    ]

    ` 

获取mysqli

    //start
    <?php

    if(isset($_POST['action']))
    {
include('connectionmysqli.php');

$output = '';

if($_POST['action'] == 'fee_type')
{
$query = mysqli_query("
SELECT fee FROM sch_fee 
WHERE fee_type = $fee_type");
    //$output = '';
    //$query = $mysqli->query("SELECT * FROM tbl_comment
    //WHERE parent_comment_id = '0'  
    //ORDER BY comment_id DESC");
    $result = mysqli_execute_query(
     array(
    $fee_type   =>  $_POST["query"]
    )
    );
    //$result = $query->fetch_all(MYSQLI_ASSOC);
    // $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
    $row = mysqli_fetch_assoc($result);
    $output .= '<option value="">Select State</option>';
    foreach($result as $row)
    {
    $output .= '<option value="'.$row["fee"].'">'.$row["fee"].'</option>';
}
    echo $output;
    }}
    ?>
    

插入mysqli.php

    <?php

    //insert.php

    if(isset($_POST['fee_type']))
    {
    include('database_connection.php');

    $connection->query("INSERT INTO sch_tran (st_fullname, fee_type, fee, 
    Reciept, pay_mode,date) 
    VALUES($st_fullname,$fee_type, $fee, $Reciept, $pay_mode,$date");
    $result = mysqli_execute_query(

    array(
    $st_fullname        =>  $_POST['st_fullname'],
    $Reciept        =>  $_POST['Reciept'],
    $fee_type       =>  $_POST['fee_type'],
    $fee            =>  $_POST['fee'],
    $pay_mode       =>  $_POST['pay_mode'],
    $date   =>  date('Y:m:d H:i:s'),
    )
    );
    $result =$query->fetch_all(MYSQLI_ASSOC);

    if(isset($result))
    {
    echo 'done';
    }

    }

    ?>

    

连接mysqli.php

    <?php

    $connection = mysqli_connect('localhost','root');
    mysqli_select_db($connection,'project1');
    //$mysqli = new Mysqli("localhost","root","","project1");
    ?>
javascript php jquery mysqli
© www.soinside.com 2019 - 2024. All rights reserved.