php - 提交表单 MS SQL 和 PHP 的问题
问题描述
您好,我在将表单提交到 SQL 数据库时遇到问题我收到以下错误
我不确定这是否与会话有关,因为我试图让已登录的用户与表单一起提交,以便我稍后可以过滤它以仅向该特定用户显示详细信息。
错误如下所示
1NULL 23string(477) "INSERT INTO tbl_Impact (Schema_ID, Stakeholder_ID, Intended_Changes, Investment_Type_ID, Value_of_Investment, Summary, Outcomes_Description, Outcomes_Indicator, Outcomes_Source, Outcomes_Quantity, Outcomes_Duration, Outcomes_Start, Outcomes_Financial_Proxy, Outcomes_Value_of_Proxy, Deadweight, Displacement, Attribution, Drop_Off, UserID) VALUES (NULL, '1', '1', '1', '11', '11', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '')" 45object(PDOStatement)#5 (1) { ["queryString"]=> string(477) "INSERT INTO tbl_Impact (Schema_ID, Stakeholder_ID, Intended_Changes, Investment_Type_ID, Value_of_Investment, Summary, Outcomes_Description, Outcomes_Indicator, Outcomes_Source, Outcomes_Quantity, Outcomes_Duration, Outcomes_Start, Outcomes_Financial_Proxy, Outcomes_Value_of_Proxy, Deadweight, Displacement, Attribution, Drop_Off, UserID) VALUES (NULL, '1', '1', '1', '11', '11', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '')" }
代码
public function createSchema(){
echo "1";
//stage 1
$stakeholder = htmlspecialchars($_POST['stakeholderTextbox']);
$changes = htmlspecialchars($_POST['changesTextbox']);
//stage 2
$typeOfInvestment = htmlspecialchars($_POST['typeInvestmentTextbox']);
$valueOfInvestment = htmlspecialchars($_POST['valueInvestmentTextbox']);
$summary = htmlspecialchars($_POST['summaryTextbox']);
//stage 3
$description = htmlspecialchars($_POST['descriptionTextbox']);
$indicator = htmlspecialchars($_POST['indicatorTextbox']);
$source = htmlspecialchars($_POST['sourceTextbox']);
$quantity = htmlspecialchars($_POST['quantityTextbox']);
$duration = htmlspecialchars($_POST['durationTextbox']);
$outcomesStar = htmlspecialchars($_POST['outcomesTextbox']);
$financialProxy = htmlspecialchars($_POST['financialProxyTextbox']);
$valueProxy = htmlspecialchars($_POST['valueProxyTextbox']);
// $source2 = htmlspecialchars($_POST['source2Textbox']);
//stage 4
$deadweight = htmlspecialchars($_POST['deadweightTextbox']);
$displacement = htmlspecialchars($_POST['displacementTextbox']);
$attribution = htmlspecialchars($_POST['attributionTextbox']);
$dropOff = htmlspecialchars($_POST['dropOffTextbox']);
$userID = $_SESSION['user_id'];
var_dump($userID);
echo "2";
/* $sqlQuery = "INSERT INTO tbl_Impact (Schema_ID, Stakeholder_ID, Intended_Changes, Investment_Type_ID, Value_of_Investment, Summary, Outcomes_Description, Outcomes_Indicator, Outcomes_Source, Outcomes_Quantity, Outcomes_Duration, Outcomes_Start, Outcomes_Financial_Proxy, Outcomes_Value_of_Proxy, Deadweight, Displacement, Attribution, Drop_Off, UserID)
VALUES (NULL, '$stakeholder', '$changes', '$typeOfInvestment', '$valueOfInvestment', '$summary', '$description', '$indicator', '$source', '$quantity', '$duration', '$outcomesStar', '$financialProxy', '$valueProxy', '$source2', '$deadweight', '$displacement', '$attribution', '$dropOff', '$userID')"; */
$sqlQuery = "INSERT INTO tbl_Impact (Schema_ID, Stakeholder_ID, Intended_Changes, Investment_Type_ID, Value_of_Investment, Summary, Outcomes_Description, Outcomes_Indicator, Outcomes_Source, Outcomes_Quantity, Outcomes_Duration, Outcomes_Start, Outcomes_Financial_Proxy, Outcomes_Value_of_Proxy, Deadweight, Displacement, Attribution, Drop_Off, UserID)
VALUES (NULL, '$stakeholder', '$changes', '$typeOfInvestment', '$valueOfInvestment', '$summary', '$description', '$indicator', '$source', '$quantity', '$duration', '$outcomesStar', '$financialProxy', '$valueProxy', '$deadweight', '$displacement', '$attribution', '$dropOff', '$userID')";
echo "3";
var_dump($sqlQuery);
$statement = $this->_dbHandle->prepare($sqlQuery);
echo "4";
$statement->execute();
// $count = $statement-rowCount();
echo "5";
var_dump($statement);
}
谢谢
解决方案
您的查询语句是错误的。请将您的查询语句替换为以下内容
$sqlQuery = "INSERT INTO tbl_Impact (Schema_ID, Stakeholder_ID, Intended_Changes, Investment_Type_ID, Value_of_Investment, Summary, Outcomes_Description, Outcomes_Indicator, Outcomes_Source, Outcomes_Quantity, Outcomes_Duration, Outcomes_Start, Outcomes_Financial_Proxy, Outcomes_Value_of_Proxy, Deadweight, Displacement, Attribution, Drop_Off, UserID)
VALUES (NULL, '$stakeholder', '$changes', '$typeOfInvestment', '$valueOfInvestment', '$summary', '$description', '$indicator', '$source', $quantity', '$duration', '$outcomesStar', '$financialProxy', '$valueProxy', '$source2', '$deadweight', '$displacement', $attribution', '$dropOff', '$userID')";
推荐阅读
- react-native - HERE Maps REST API - 磁贴标签的旋转
- node.js - 使用 node/bree/bthreads 的 adhoc EPIPE 异常
- javascript - 获取的对象返回欠精细
- python - Django中的Flask网关等效
- reactjs - 在 Typescript 和 React 中为 event.target.value 使用枚举
- python - 遍历成员列表以识别同时创建的所有帐户(Python,discord.py)
- php - 连接到数据库后回显不起作用
- reactjs - 如何使用本机反应检查 Firebase 中的唯一用户名?
- python - 如何计算python中列表元素的平均值?
- android - AVD Pixel_2_API_30 的模拟器进程在 Ubuntu 上被杀死