Php 使用AJAX向数据库添加数据时遇到问题
我试图使用AJAX将数据添加到数据库中的表中,但遇到了问题。由于我的脚本现在可以正常工作,只添加了一个字段,其他字段没有添加,我不知道为什么。我知道我发布的内容存在SQL注入漏洞,但我只是想让这个演示项目的功能正常工作 HTML //在处理文件中Php 使用AJAX向数据库添加数据时遇到问题,php,jquery,ajax,Php,Jquery,Ajax,我试图使用AJAX将数据添加到数据库中的表中,但遇到了问题。由于我的脚本现在可以正常工作,只添加了一个字段,其他字段没有添加,我不知道为什么。我知道我发布的内容存在SQL注入漏洞,但我只是想让这个演示项目的功能正常工作 HTML //在处理文件中 ob_start(); require("../includes/header.php"); if($_POST["save"]){ header("Location: ../pages/instructor.php")
ob_start();
require("../includes/header.php");
if($_POST["save"]){
header("Location: ../pages/instructor.php");
$instructor = $_POST["name"];
$initials = $_POST["initials"];
$date = $_POST["date"];
$center = $_POST["center_menu"];
$pair1 = $_POST["pair1"];
$pair2 = $_POST["pair2"];
$scenario = $pair1 .$pair2;
$id = $scenario .substr(strtoupper($center, 0,4)) .$date .$initials;
$system = $_REQUEST["system"];
$description = $_REQUEST["description"];
$breaker = $_REQUEST["breaker"];
ob_clean();
$insert_malfunctions = "INSERT INTO `$malfunctions`(`scenario_id`, `system`, `description`, `breaker`) VALUES('" .$id ."', '" .$system ."', '" .$description ."', '" .$breaker ."')";
mysqli_query($connect, $insert_malfunctions);
echo json_encode(array("success" => 1));
}
我在处理脚本中还有两个额外的查询,它们将数据添加到其他表中,但我认为它们不会造成问题。另外,让PHP检查submit按钮的post值是否会产生问题?现在,添加到数据库中的唯一字段是scenario_id字段
这是我收到的网络回复。
将页眉放在插入后的末尾,因为页眉在插入前重定向页面,因此会丢失post数据
header("Location: ../pages/instructor.php");
也要改变这一点,
$insert_malfunctions = "INSERT INTO " . $malfunctions . "( scenario_id, system, description, breaker) VALUES('" .$id ."', '" .$system ."', '" .$description ."', '" .$breaker ."')";
不确定为什么需要我的HTML,因为这与问题无关,但我会添加它。哪个字段正确添加到表中?检查浏览器控制台网络选项卡中的实际请求,查看实际发送的内容以及如何执行?在firefox中使用Firebug
ob_start();
require("../includes/header.php");
if($_POST["save"]){
header("Location: ../pages/instructor.php");
$instructor = $_POST["name"];
$initials = $_POST["initials"];
$date = $_POST["date"];
$center = $_POST["center_menu"];
$pair1 = $_POST["pair1"];
$pair2 = $_POST["pair2"];
$scenario = $pair1 .$pair2;
$id = $scenario .substr(strtoupper($center, 0,4)) .$date .$initials;
$system = $_REQUEST["system"];
$description = $_REQUEST["description"];
$breaker = $_REQUEST["breaker"];
ob_clean();
$insert_malfunctions = "INSERT INTO `$malfunctions`(`scenario_id`, `system`, `description`, `breaker`) VALUES('" .$id ."', '" .$system ."', '" .$description ."', '" .$breaker ."')";
mysqli_query($connect, $insert_malfunctions);
echo json_encode(array("success" => 1));
}
header("Location: ../pages/instructor.php");
$insert_malfunctions = "INSERT INTO " . $malfunctions . "( scenario_id, system, description, breaker) VALUES('" .$id ."', '" .$system ."', '" .$description ."', '" .$breaker ."')";