如何在 MSSQL 中调试资源 #6 错误

How do I debug Resource #6 error in MSSQL?

本文关键字:资源 错误 调试 MSSQL      更新时间:2023-09-26

>我有一对单选按钮,我想以bit的形式将其值插入我的数据库中。以下是相同的HTML代码。

<form  id="Form" method="post" class="overlay"  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" >
<input type="hidden" id="Keyy" name="key" value="">
<label for="JRadioYes">Active? Yes</label> <input type="radio" id="JRadioYes" name="activeradio"<?php if (isset($ActiveValue) && $ActiveValue == "yes") echo "checked='checked' "; ?>value="yes"> 
        <label for="JRadioNo">No</label> <input type="radio" id="JRadioNo" name="activeradio"<?php if (isset($ActiveValue) && $ActiveValue == "no") echo "checked='checked' "; ?>value="no">
<input type="submit" id="submitter" name="sub" value="Submit!" onclick="decider(this)">
</form>

以下是插入数据库的 PHP 代码

// Check if radio is submitted
if (isset ( $_POST ["activeradio"])) 
{
    //Extract values from $_POST and store in variables
    $select_radio = $_POST ["activeradio"];
    if ($select_radio == "yes") {
        $active_status = true;
        //I also tried assigning 1 instead of true
    }
    if ($select_radio == "no") {
        $active_status = false;
        //I also tried assigning 0 instead of false
    }
    if($_POST["key"] == "update")
    {
        try
        {
            echo "<script type='text/javascript'>
                alert('$active_status');
                </script>";
            $JobInt = intval($JobTypeID);
            $stmt = sqlsrv_query ( $conn, 'EXEC spEditThisJobType @Active = ?', array (
                $active_status
            ) );
        }
        catch(Exception $e)
        {
            echo "Error :". $e;
        }
        if($stmt != null)
        {
            echo "<script type='text/javascript'>alert('Successfully Updated!$stmt');
            </script>";
        }
    }
}

我能够收到显示已成功更新的警报,但我也收到资源#6错误。此外,数据库不会更新。

我在这里犯了什么错误?请指导我。提前谢谢你。

查看sqlsrv_query的文档 - 它返回资源对象,而不是查询结果。

因此,当您回显"Successfully Updated!$stmt" 时,资源$stmt将转换为其字符串表示形式 - Resource #6

因此,您要么需要从回显中删除$stmt,要么对资源执行某些操作,例如使用 sqlsrv_fetch_array 读取数据。