I have a pair of radio buttons and I want to insert its value into my database in the form of bit
. Following is the HTML code for the same.
<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>
The following is the PHP code for inserting into the database
// 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>";
}
}
}
I am able to get the alert which says Successfully Updated, but I am also getting Resource #6 error along with it. Also the database does not get updated.
What is the mistake I have done here? Please guide me. Thank you in advance.
Have a look at the documentation for sqlsrv_query
- it returns a resource object, not the result of the query.
Therefore when you echo "Successfully Updated!$stmt"
, the resource $stmt
is converted to its string representation - Resource #6
.
So you either need to remove $stmt
from your echo, or do something with the resource such as reading the data using sqlsrv_fetch_array
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.