Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8413049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:50:13+00:00 2026-06-10T00:50:13+00:00

I want to update the database with a checkbox in checked state. If it

  • 0

I want to update the database with a checkbox in checked state.

  • If it is checked then update the database with 1.
  • Else if it is unchecked then update it with 0.

It works fine but it doesn’t work if unchecked.

<?php 
include('lib/db.php');

$facebook_id ="10001088";
$query1 = "SELECT `video`,`quran`,`medical`,`groups`  FROM `man_facebook`.`users` WHERE `facebook_id`='$facebook_id'";
        $result1 = mysql_query($query1);
while($result = mysql_fetch_array($result1))
{
    $video = $result['video'];
    $quran = $result['quran'];
    $medical = $result['medical'];
    $groups = $result['groups'];
    echo $video;
 //   echo $quran;
?>

<form method="post"  action="<? echo $_SERVER['REQUEST_URI']; ?>" >

<input type="checkbox" name="video" id="video" value="<?echo $video;?>" <?php
if($video == '1'){
     echo "checked='checked'";
}
 else {}
echo "/>"
?> 
 <input type="submit" name="submit" value="Submit">
</form>

<?php
}
 if (isset($_POST['submit']))
{
 if (is_numeric($_POST['video']) && $_POST['video'] <2 )
{
 $video1 = isset($_POST['video']) ? '1' : '0';


 echo $video1;
    $query = mysql_query("UPDATE `man_facebook`.`users` 
SET `video` ='$video1'
WHERE `facebook_id`='$facebook_id'");

$video = $video1;
echo '<meta http-equiv="refresh" content="0" />';

    }
    }
//echo $query;
 //header("Location: updatesql.php"); 

?>

Can I also use jquery to update it smoothly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:50:15+00:00Added an answer on June 10, 2026 at 12:50 am

    I find this part a bit weird:

    if (is_numeric($_POST['video']) && $_POST['video'] <2 )
    {
        $video1 = isset($_POST['video']) ? '1' : '0';
    

    You first check if it is numeric and then check if it is set. If it wasn’t set, that if would become false automatically. In other words, $video is always 1. Assuming $video can be only true/false (or maybe it comes as “checked”/”unchecked”, not really sure), use it like this:

    $video1 = ($video ? '1' : '0');
    

    Hopefully I spotted the issue successfully 🙂

    UPDATE

    <input type="checkbox" name="video" id="video" value="video" <?php
    if($video == '1'){
         echo "checked='checked'";
    }
    echo "/>";
    
    ...
    
    if (isset($_POST['submit']))
    {
        echo $_POST['video']; // again, please tell what it outputs here!!!
        $video1 = (($_POST['video'] == "video") ? '1' : '0');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My customer doesn't want a database but would prefer to update their data in
i want to update my sqlite database but i cannot find the way to
I have function to detect idle state of user. I want to update database
Basically i want to update my database with values from an array that i
i want to update all records in my database(mongodb),I tried to use command below
I want to always update the value of an update row in the database.
So, I want to insert this query into the database file: UPDATE contas SET
I want to do an update statement in my database, after an element gets
I want to update a database in my asp.net application. The updated fields are
I have a MySQL database that I want to update with a response value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.