首页 > 解决方案 > 在php的数据库中的同一行中插入具有相同名称的表单输入值

问题描述

我在这里多次尝试将输入输入数据库。如您所见,条目是可变的。像这样的代码

<?php 
        
    $WALLETS_query = $db->query("SELECT * FROM wallets");
    $WALLET_EXIST  = $WALLETS_query->num_rows;

    while ($WALLET = $WALLETS_query->fetch_assoc() ) {
        $table_name                 =   $WALLET['table_name'];
        $wallet_name                =   $WALLET['wallet_name'];
        $wallet_currency            =   $WALLET['wallet_currency'];
        $wallet_currency_symbole    =   $WALLET['wallet_currency_symbole'];
        $wallet_instructions        =   $WALLET['wallet_instructions'];
        $add_date                   =   $WALLET['add_date'];
        $status                     =   $WALLET['status'];
        
        echo "
            <div class='col-md-12 col-lg-12'>
                <div class='form-group'>
                    <label class='form-label'> Price in $wallet_currency ($wallet_currency)</label>
                    <input type='number' class='form-control' name='game_price[$wallet_currency][]' id='game_$wallet_currency' placeholder='Price in $wallet_currency_symbole '>
                </div>
            </div>";
    }
?>

我必须注意,输入的数量与表(钱包)中的条目数量有关,因此输入是可变的,名称也是如此,我想将输入值正确输入到数据库中。

// Add New Game
if (isset($_POST['add_new_game'])) {
    $GAME_selected_game_type        =       $_POST['selected_game_type'];
    $GAME_game_title                =       $_POST['game_title'];
    $GAME_game_quantity             =       $_POST['game_quantity'];
    $GAME_game_price                =       $_POST['game_price'];
    $Date                           =       date('Y-m-d');


    $wallets = Query_db_table("SELECT * FROM wallets");
    foreach($wallets as $wallet){}



    $DATA = array(
        'type'              => $GAME_NAME, 
        'name'              => $Date, 
        'price'             => $GAME_game_price,
        'status'            => 1
    );

    //Insert Information to database
    dbRowInsert("games",$DATA);
    header("Location: $_SERVER[PHP_SELF]");

}else{

}

太感谢了

标签: phpmysql

解决方案


推荐阅读