首页 > 解决方案 > 提交表单 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);
    }

谢谢

MS SQL 数据库中的表

标签: phpsql-server

解决方案


您的查询语句是错误的。请将您的查询语句替换为以下内容

 $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')";

推荐阅读