我有一对单选按钮,我想以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的错误与它。此外,数据库不会被更新。
我在这里犯了什么错误?请引导我。提前谢谢你。
发布于 2015-02-02 14:03:24
查看一下sqlsrv_query的文档-它返回一个资源对象,而不是查询的结果。
因此,当回送"Successfully Updated!$stmt"时,资源$stmt被转换为其字符串表示形式- Resource #6。
因此,您要么需要从回显中删除$stmt,要么对资源执行一些操作,比如使用sqlsrv_fetch_array读取数据。
https://stackoverflow.com/questions/28279198
复制相似问题