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 8305653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:09:38+00:00 2026-06-08T18:09:38+00:00

Here’s my problem: I have an html template with a checkbox. When the php

  • 0

Here’s my problem: I have an html template with a checkbox. When the php script runs, it passes a value to the checkbox’s “checked” property like this:

<input type="checkbox" name="form_data[show_products]" {SHOW_PRODUCTS} />

where {SHOW_PRODUCTS} can be either 'checked="true"' or '', depending on whether the data in the database column is 1 or 0. So, in other words, the checkbox is checked, or unchecked, in accordance with the data passed from the database.

Now, since this is the template for the edit form, I need to gather the value of the “checked” property and pass it to the database. However, if I uncheck the checkbox that has been checked automatically at page load and try to save changes, the script still writes 1 to the database instead of 0. How can I change this?

EDIT

These are the php parts that handle the data:

else if (isset($_POST['edit']))
{   
    $form_data = $_POST['form_data'];
    $present_id = $form_data['present_id']; 
    $present=new Present();
    $present->load($present_id); 

    if (isValidForm())
        {       
        $present->set($form_data);
        $present->update();
        }
    else
        {
        $errors=$formValidator->getErrors();
        $page_content_HTML=edit_form_HTML($form_data, $errors);
        }
}

function set($data){
    $keys=array_keys($data);
    foreach($keys as $key)
    {
        $this->$key=$data[$key];
    }   
}

function update(){
        global $db;
        $date_from = format_datetime($this->date_from, "%Y.%m.%d. %H:%M:%S");
        $date_to = format_datetime($this->date_to, "%Y.%m.%d. %H:%M:%S");
        $sql="UPDATE presents SET present_name='".$this->present_name."', description='".$this->description."', present_image='".$this->present_image."', date_from='".$date_from."', date_to='".$date_to."', short_description='".$this->short_description."', show_products='".$this->show_products."' WHERE present_id='$this->present_id'";
        $db->query($sql);

}
  • 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-08T18:09:40+00:00Added an answer on June 8, 2026 at 6:09 pm

    The problem is not the form / checkbox but how you handle the request data in your PHP script. As I commented before: An unchecked checkbox is not part of the POST or GET request (it’s not just empty but it’s not existent).

    Therefore, $this->show_products does not exist when the box is unchecked.

    Try following: Add the line

    $present->show_products = 0;
    

    right before

    $present->set($form_data);
    

    This makes show_products default to “off” (“0”) and it only gets overwritten if the checkbox is checked.

    (Btw: I also think, if the CB is checked that the value will be “on” an not “1”. Add the attribute value="1" to the checkbox tag to make it “1” instead).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is my problem : I have a post controller with the action create.
Here is the problem that I am trying to solve. I have two folders
Here is what I am trying to achieve in PHP: I have this string:
Here's a problem I ran into recently. I have attributes strings of the form
Here's a coding problem for those that like this kind of thing. Let's see
Here's my situation: I have a Data Template set up which contains a ToggleButton
Here is a broken down version of my problem : I have a method.
Here the problem. I have an ItemsControl , and I want to show a
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>

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.