Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用javascript添加新的表单行并插入到数据库中_Javascript_Php_Jquery_Mysql - Fatal编程技术网

尝试使用javascript添加新的表单行并插入到数据库中

尝试使用javascript添加新的表单行并插入到数据库中,javascript,php,jquery,mysql,Javascript,Php,Jquery,Mysql,添加新行可以工作(它添加了一个新行),但是当我尝试将数据提交到数据库时,它会返回数组。我尝试了一下,没有在表单中的名称标签末尾添加[],但它提交的只是第一行 很抱歉问了一个愚蠢的问题,但我一直在绞尽脑汁想如何让它发挥作用 这是我的密码: <?php if($user->data()->username = $res->username) { if(isset($_POST['results'])) { $submitres

添加新行可以工作(它添加了一个新行),但是当我尝试将数据提交到数据库时,它会返回数组。我尝试了一下,没有在表单中的名称标签末尾添加[],但它提交的只是第一行

很抱歉问了一个愚蠢的问题,但我一直在绞尽脑汁想如何让它发挥作用

这是我的密码:

<?php
    if($user->data()->username = $res->username) {
        if(isset($_POST['results'])) {
            $submitres = DB::getInstance()->insert('results', array(
                'torneyid'      => Input::get('torneyid'),
                'buyin'         => Input::get('buyin'),
                'torneydesc'    => Input::get('description'),
                'finish'        => Input::get('finish'),
                'profit_loss'   => Input::get('profit'),
                'eventid'       => $res->id
                    ));
        }
        echo '<form action="" method="post">
        <table id="mytable" class="table table-striped">
        <thead>
            <tr>
                <th>Torney ID</th>
                <th class="hidden-sm">Torney Description</th>
                <th>Buy-In</th>
                <th>Finish Pos</th>
                <th>Profit/Loss</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><input name="torneyid[]" type="text" value="" class="form-control" /></td>
                <td class="hidden-sm"><input name="description[]" type="text" value="" class="fm-control" /></td>
                <td><input name="buyin[]" type="text" value="" class="form-control" /></td>
                <td><input name="finish[]" type="text" value="" class="form-control" /></td>
                <td><input name="profit[]" type="text" value="" class="form-control" /></td>
            </tr>
        </tbody>
    </table>
    <button type="submit" name="results" class="btn btn-primary">Submit Results</button>
    <a id="add"><button class="btn btn-primary">Add Row</button></a>
        </form>';
    } 

我的java脚本是:

<script type="text/javascript">
    $(document).ready(function() {
        $("#add").click(function() {
        $('#mytable tbody>tr:last').clone(true).insertAfter('#mytable tbody>tr:last');
    return false;
    });
    });
</script>

$(文档).ready(函数(){
$(“#添加”)。单击(函数(){
$('#mytable tbody>tr:last').clone(true).insertAfter('#mytable tbody>tr:last');
返回false;
});
});
谢谢你的帮助

已修复-将添加我的操作方式,以防它对fuiture中的其他人有所帮助:

将代码从if(isset)更改为:

if(isset($\u POST['results'])){
对于($row=0;$rowinsert('results',array(
“torneyid”=>tid美元,
“buyin”=>$desc,
“torneydesc”=>美元购买,
“完成”=>$fin,
“损益”=>$prof,
'eventid'=>$res->id
));
}

torneyid的数组上循环,并使用索引为每个数组创建插入row@charlietfl你能给我举个例子吗?或者在某个地方我能明白你的意思吗?对不起,我有点笨,你明白了吗
if(isset($_POST['results'])) {
    for ( $row = 0; $row < count( $_POST["torneyid"] ); ++$row ) {
        $tid = $_POST["torneyid"][$row];
        $desc = $_POST["description"][$row];
        $buy = $_POST['buyin'][$row];
        $fin = $_POST['finish'][$row];
        $prof = $_POST['profit'][$row];

    $submitres = DB::getInstance()->insert('results', array(
        'torneyid'      => $tid,
        'buyin'         => $desc,
        'torneydesc'    => $buy,
        'finish'        => $fin,
        'profit_loss'   => $prof,
        'eventid'       => $res->id

        ));
}