提交表格MS SQL和PHP的问题

时间:2018-07-27 14:06:09

标签: php sql-server

您好,我在将表单提交到SQL数据库时遇到问题,出现以下错误

我不确定是否与会话有关,因为我试图让登录的用户提交表单,以便以后可以对其进行过滤以仅向该特定用户显示详细信息。< / p>

错误显示在下方

   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);
    }

谢谢

TABLE IN MS SQL DATABASE

1 个答案:

答案 0 :(得分:0)

您的查询语句错误。请使用以下内容替换您的查询语句

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