我试图将变量可变数据发送到数据库中,但是数据没有被发送。我使用jQuery $ .post函数发送数据,因此我假设问题出在那里,但是,我不确定所说的问题是什么。此外,我知道此时我有SQL注入问题。
的jQuery
function verify(){
center = $("#center_menu").val();
initials = $("#initials").val();
date = $("#date").val();
recurrent = $("#recurrent_menu").val();
name = $("#name").val();
email = $("#email").val();
aircraft = $("#aircraft_menu").val();
pair1 = $("#pair1").val();
pair2 = $("#pair2").val();
id = scenario +center_sub +date +initials;
center_sub = center.substring(0,4);
scenario = pair1 +" " +pair2;
jep_num = 0;
$("#air_id, #chart_id, #chart_desc").children().remove();
$(".jepp_charts").each(function(ind,item){
jep_num = ind + 1;
air_id = $("#air_id_" +jep_num).val();
chart_id = $("#chart_id_" +jep_num).val();
chart_desc = $("#chart_desc_" +jep_num).val();
$("#air_id").append("<div id='air_id_field_" +jep_num +"' name='air_id_field_" +jep_num +"' class='table_field'><strong>Airport Identifier: </strong>" +air_id +"</div>");
$("#chart_id").append("<div id='chart_id_field_" +jep_num +"' name='chart_id_field_" +jep_num +"' class='table_field'><strong>Chart Identifier: </strong>" +chart_id +"</div>");
$("#chart_desc").append("<div id='chart_desc_field_" +jep_num +"' name='chart_desc_field_" +jep_num +"' class='table_field'><strong>Chart Description: </strong>" +chart_desc +"</div>");
})
$("input[id='save']").on("click", function(){
verify();
$.post("../php/processing.php", {scenario: scenario, instructor: name, initials: initials, email: email, date: date, center: center, aircraft: aircraft, recurrent: recurrent, pair1: pair1, pair2: pair2, jepaid: air_id, jepcid: chart_id, jepdesc: chart_desc}, function(response){
if(response.success == "1"){
}
}, "json");
})
Php表格处理
ob_start();
require("../includes/header.php");
if($_SERVER["REQUEST_METHOD"] == "POST"){
$instructor = $_SESSION["user"];
$initials = $_POST["initials"];
$email = $_SESSION["email"];
$date = $_POST["date"];
$center = $_POST["center"];
$aircraft = $_POST["aircraft"];
$recurrent = $_POST["recurrent"];
$pair1 = $_POST["pair1"];
$pair2 = $_POST["pair2"];
$scenario = $pair1 ." " .$pair2;
for($i = 1; $i <= 5; $i++){
$jepaid = "air_id_{$i}";
$jepcid = "chart_id_{$i}";
$jepdesc = "chart_desc_{$i}";
if(isset($_POST[$jepaid])){
GLOBAL $$jepaid = $_POST[$jepaid];
GLOBAL $$jepcid = $_POST[$jepcid];
GLOBAL $$jepdesc = $_POST[$jepdesc];
}
}
$query = "INSERT INTO `$scenarios`(`scenario`, `instructor`, `initials`, `email`, `created`, `center`, `aircraft`, `recurrent`, `city_pair1`, `city_pair2`, `air_id`, `chart_id`, `chart_desc`) VALUES('" .$scenario ."', '" .$instructor ."', '" .$initials ."', '" .$email ."', '" .$date ."', '" .$center ."', '" .$aircraft ."', '" .$recurrent ."', '" .$pair1 ."', '" .$pair2 ."', '" .$$jepaid ."', '" .$$jepcid ."', '" .$$jepdesc ."')";
mysqli_query($connect, $query);
}
ob_clean();
echo json_encode(array("success" => 1));
数据库表创建
$create_table_scenarios = "CREATE TABLE IF NOT EXISTS $scenarios(scenario VARCHAR(25), instructor VARCHAR(50), initials VARCHAR(3), email VARCHAR(50), created VARCHAR(25), center VARCHAR(25), aircraft VARCHAR(25), recurrent VARCHAR(50), city_pair1 VARCHAR(10), city_pair2 VARCHAR(10), air_id VARCHAR(50), chart_id VARCHAR(50), chart_desc VARCHAR(50))";
HTML表单(不是整个表单,只是问题区域)
<div id="form_jepp" class="form_view">
<div id="charts">
<h3>Jeppeson Charts</h3>
<div class="jepp_charts">
<fieldset>
<label>Airport Identifier</label>
<input type="text" class="air-id-input" name="air_id_1" id="air_id_1" />
</fieldset>
<fieldset>
<label>Chart Identifier</label>
<input type="text" class="chart-id-input" name="chart_id_1" id="chart_id_1" />
</fieldset>
<fieldset>
<label>Chart Description</label>
<input type="text" class="chart-desc-input" name="chart_desc_1" id="chart_desc_1" />
</fieldset>
</div>
</div>
<div id="add">
<label for="add_chart">Add Chart: </label>
<button id="add_chart" name="add_chart">+</button>
</div>
</div>
答案 0 :(得分:0)
Too many code for me, but any way here is some advice for you. 1. Put all your fields into form with id="form_jepp", and your button with id="add_chart" make it type="submit" 2. then in jquery you have to do only simple code as follows:
$.post("../php/processing.php", $('#form_jepp').serialize(), function(response){
if(response.success == "1"){ //blah blah
});
3. comment all your code in 'Php Form Processing' then start by debugging the $_POST value simply by using
print_r($_POST);
4.如果您看到所有值,则继续进行验证和数据插入。