我想提交一个Bootstrap表单,其中包含一个动态复选框字段,该字段包含来自另一个表字段的数据,我希望它通过JQuery的ajax发送给PHP。请告诉我如何使用ajax函数从bootstrap模态中获取数据。这是我的代码。 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 code
<?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!";
/*}*/
}
&GT;
答案 0 :(得分:0)
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){
}
})
}