Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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
通过ajax表单引导表单将动态复选框值发送到php_Php_Jquery_Sql Server_Ajax_Bootstrap Modal - Fatal编程技术网

通过ajax表单引导表单将动态复选框值发送到php

通过ajax表单引导表单将动态复选框值发送到php,php,jquery,sql-server,ajax,bootstrap-modal,Php,Jquery,Sql Server,Ajax,Bootstrap Modal,我想提交一个包含动态复选框字段的引导表单,该字段包含来自另一个表字段的数据,我想通过JQuery的ajax将其发送到PHP。请告诉我如何使用ajax函数从引导模式获取数据。这是我的代码。 HTML代码 <div class="form-group" id="myResponse"> <label for="event1">Event</label> <?php

我想提交一个包含动态复选框字段的引导表单,该字段包含来自另一个表字段的数据,我想通过JQuery的ajax将其发送到PHP。请告诉我如何使用ajax函数从引导模式获取数据。这是我的代码。 HTML代码

<div class="form-group" id="myResponse">
                <label for="event1">Event</label>
                <?php
                    $sql = "SELECT event_name FROM event1";
                    $stmt = sqlsrv_query($conn, $sql);
                    if( $stmt === false) 
                    {
                       die( print_r( sqlsrv_errors(), true));
                    }

                    $numFields = sqlsrv_num_fields($stmt);

                    while(sqlsrv_fetch($stmt)) 
                    {
                       // Iterate through the fields of each row.
                       for($i = 0; $i < $numFields; $i++) 
                        { 
                            echo '<input type="checkbox" name="event[]"/>'." ";
                            echo sqlsrv_get_field($stmt, $i)." ";

                        }
                       echo "<br />";
                    }
                ?>  
            </div>

事件
php代码

<?php
//Database inclusion
include_once 'db_connection.php';
//get values
if(isset($_POST['addGuest']))
{   
    $first_name     =   $_POST['first_name'];
    $last_name      =   $_POST['last_name'];
    $email          =   $_POST['email'];
    $event1         =   $_POST['event1'];

    //name can contain only alpha characters and space
    /*if (isset($_POST['addRecord'])) 
    {*/
        $tsql = "INSERT INTO dbo.demo (first_name, last_name, email, event1) values (?, ?, ?, ?)";
        $var = array($first_name, $last_name, $email ,$event1 );
        $stmt = sqlsrv_query( $conn, $tsql, $var);
        if( $stmt === false ) 
        {
            die( print_r( sqlsrv_errors(), true));
        }
        echo $successmsg = "Successfully Registered!";
    /*}*/
}

的可能重复项
    Hi first of all change this filed to and onsubmit call addform button

    $event1         =   $_POST['event'];

    enter code here

 function addform()
{
$.ajax({
            url : 'process.php',
            type : 'POST',
            data : $('#form').serialize(),
            success: function(data){





            }
})

}