在Mysql数据库和显示数据提交的消息中插入动态选择框值

在下面的表单中,我将根据资产标题值从mysql数据库加载问题和答案,并向数据库提交动态自定义问题值。 (这工作正常)但我的问题是,当表单值被提交到数据库时,我没有收到消息,对于少于15个自定义问题的资产。

我猜我在createlead.php文件中做错了,如果条件……

请帮忙。

如果您认为这个问题可以通过其他方法解决,请告诉我。

在此处输入图像描述 在此处输入图像描述 根据资产标题值从mysql数据库加载动态自定义问题

<?php //load_data.php $connect = mysqli_connect("localhost", "root", "", "test"); $output = ''; if(isset($_POST["assetid"])) { if($_POST["assetid"] != '') { $sql = "SELECT * FROM cq WHERE assetid = '".$_POST["assetid"]."'"; } else { $sql = "SELECT * FROM cq WHERE assetid = 'akash'"; // i dont want to load any database so used wrong query } $result = mysqli_query($connect, $sql); $quesno = 1; while($row = mysqli_fetch_array($result)) { $output .= '
'; $output .= '
'; $output .= ''; $output .= ''; // $output .= '
'.$row["product_name"].'
'; // $output .= ''.$row["cqname"].'
'; $output .= 'Select Custom Question Answer '.$row["cqa1"].' '.$row["cqa2"].' '.$row["cqa3"].' '.$row["cqa4"].' '.$row["cqa5"].' '.$row["cqa6"].' '.$row["cqa7"].' '.$row["cqa8"].' '.$row["cqa9"].' '.$row["cqa10"].' '.$row["cqa11"].' '.$row["cqa12"].' '.$row["cqa13"].' '.$row["cqa14"].' '.$row["cqa15"].' '.$row["cqa16"].' '.$row["cqa17"].' '.$row["cqa18"].' '.$row["cqa19"].' '.$row["cqa20"].' '.$row["cqa21"].' '; // $output .= '
'; $output .= '
'; $quesno++; } echo $output; } ?>

Jquery(将表单字段值发送到php文件): –

 $(document).ready(function() { // submit form $("#newleadform").unbind('submit').bind('submit', function() { $(".text-danger").remove(); var form = $(this); // validation var assettitle = $("#assettitle").val(); var customquestion1 = $("#cq1").val(); var customquestion2 = $("#cq2").val(); var customquestion3 = $("#cq3").val(); var customquestion4 = $("#cq4").val(); var customquestion5 = $("#cq5").val(); var customquestion6 = $("#cq6").val(); var customquestion7 = $("#cq7").val(); var customquestion8 = $("#cq8").val(); var customquestion9 = $("#cq9").val(); var customquestion10 = $("#cq10").val(); var customquestion11 = $("#cq11").val(); var customquestion12 = $("#cq12").val(); var customquestion13 = $("#cq13").val(); var customquestion14 = $("#cq14").val(); var customquestion15 = $("#cq15").val(); if(assettitle) { //submit the form to server $.ajax({ url : '../pages/php_action/addnewlead/createlead.php', type : 'POST', data : form.serialize(), dataType : 'json', success:function(response) { // remove the error $(".form-group").removeClass('has-error').removeClass('has-success'); if(response.success == true) { $(".messages").html(''); // reset the form $("#newleadform")[0].reset(); } else { $(".messages").html(''); } // /else } // success }); // ajax subit } /// if return false; }); // /submit form for create member }); // /add modal 

createlead.php(将表单字段值提交给数据库): –

  false, 'messages' => array()); $assettitle= $_POST['assettitle']; $customquestion1= $_POST['cq1']; $customquestion2= $_POST['cq2']; $customquestion3= $_POST['cq3']; $customquestion4= $_POST['cq4']; $customquestion5= $_POST['cq5']; $customquestion6= $_POST['cq6']; $customquestion7= $_POST['cq7']; $customquestion8= $_POST['cq8']; $customquestion9= $_POST['cq9']; $customquestion10= $_POST['cq10']; $customquestion11= $_POST['cq11']; $customquestion12= $_POST['cq12']; $customquestion13= $_POST['cq13']; $customquestion14= $_POST['cq14']; $customquestion15= $_POST['cq15']; $sql = "INSERT INTO ltfs (assettitle, customquestion1, customquestion2, customquestion3, customquestion4, customquestion5, customquestion6, customquestion7, customquestion8, customquestion9, customquestion10, customquestion11, customquestion12, customquestion13, customquestion14, customquestion15) VALUES ('$assettitle', '$customquestion1', '$customquestion2', '$customquestion3', '$customquestion4', '$customquestion5', '$customquestion6', '$customquestion7', '$customquestion8', '$customquestion9', '$customquestion10', '$customquestion11', '$customquestion12', '$customquestion13', '$customquestion14', '$customquestion15')"; $query = $connect->query($sql); if($query === TRUE) { $validator['success'] = true; $validator['messages'] = "Your lead successfully submited to quality team"; } else { $validator['success'] = false; $validator['messages'] = "Error while adding the lead information"; } // close the database connection $connect->close(); echo json_encode($validator); } 

我觉得这里搞错了

 if($query === TRUE) 

你可以这样做

 if($query){//you message}else{//error message}