有人可以帮助我找出为什么我在这段代码中得到500错误我是初学者

时间:2015-12-11 08:16:12

标签: php pdo

我收到了由以下代码生成的HTTP错误500:

else if ($_POST['submit'] == "button2") {
    $tbVraag = $_POST['tbVraag'];
    $tbText = $_POST['tbText'];
    $tbQuestId = $_POST['tbQuestId'];


    $UpdateQuest = "UPDATE Vragen SET Title=:Title, `Text`=:txt WHERE QuestionId=:QuestionId";
    $stmt = $dbQuiz->prepare($UpdateQuest);

    $stmt->bindparam(':Title', $tbVraag);
    $stmt->bindparam(':txt', $tbText);
    $stmt->bindparam(':QuestionId', $tbQuestId);
    $stmt->execute();

    $tbAnt1 = $_POST['tbAnt1'];

    $UpdateAnt = "UPDATE Antwoorden SET `Text`=:antTxt WHERE AnswerId= ?";
    $statement = $dbQuiz->prepare($UpdateAnt);

    $statement->bindparam(':antTxt,', $tbAnt1);
    $statement->execute();

    echo "Update successfully completed!";

}

我怀疑错误是由代码中的第二个问题引起的。以下是我收到的错误消息:

  

致命错误:未捕获的异常' PDOException'与消息   ' SQLSTATE [HY093]:参数号无效:混合命名和位置   参数'在   /home/lab/domains/u-approachlab.nl/public_html/blendi/Website/opslaan.php:81   堆栈跟踪:#0   /home/lab/domains/u-approachlab.nl/public_html/blendi/Website/opslaan.php(81):   PDOStatement-> execute()#1 {main}抛出

1 个答案:

答案 0 :(得分:1)

问题是第二个查询中的问号:

<?php
class AppFile extends AppModel {

    public $name = 'File';

    public $alias = 'File';

    public $table = 'files';

}

您添加了一个问号,但绝不会将其绑定为参数。

你应该使用这样的东西:

    // <summary>
    // check that the compiler is in a build mode that enables documentation analysis.
    // it's not clear when this is off, but command line builds, and full rebuilds
    // seem to have it turned off from time to time.
    // </summary>
    internal static bool IsDocumentationModeOn(this SyntaxNodeAnalysisContext context)
    {
        return context.Node.SyntaxTree?.Options.DocumentationMode 
               != DocumentationMode.None;
    }

然后还将其添加为参数:

$UpdateAnt = "UPDATE Antwoorden SET `Text`=:antTxt WHERE AnswerId= ?";
$statement = $dbQuiz->prepare($UpdateAnt);

$statement->bindparam(':antTxt,', $tbAnt1);
$statement->execute();

我的代码中没有看到任何$UpdateAnt = "UPDATE Antwoorden SET `Text`=:antTxt WHERE AnswerId= :answerId"; ,所以你需要以某种方式得到它。