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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:37:17+00:00 2026-05-16T16:37:17+00:00

I have two forms a) post.php b) edit.php I am using the checkbox in

  • 0

I have two forms

a) post.php
b) edit.php

I am using the checkbox in both the form to set the binary value (0 and 1) to set the status for approve.

to process the value from the checkbox in the post.php I am using the code which checks and assume that if the checkbox is checked then the value will be 1 other wise it is 0 by default

if (isset($_POST['ad_approve'])) $ad_approve  = htmlspecialchars(strip_tags(mysql_real_escape_string($_POST['ad_approve'])));
        else { $ad_approve = 0; }

Now in the edit.php form I retrieve the data from the database and set the checkbox accordingly . if the approve has the value 1 then it is checked by default . look onto the following code

<input name="ad_approve" type="checkbox" value="1" <?php if($approve==1) echo 'checked="checked"';?> />

in the above code I cannot apply the same logic to catch the value from ad_approve i.e(by checking isset()) because if the value is 1 by default and if I try unchecking the checkbox then automatically the program assume that the value is set because it has been changed from checked to unchecked. now in the edit.php how do I again process the value from it such that if the checkbox is checked hold the value as 1 otherwise 0, ??

  • 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-05-16T16:37:18+00:00Added an answer on May 16, 2026 at 4:37 pm

    to be honest your question does not make a whole lot of sense but I can understand that you wish to check if check boxes are actually set.

    firstly you don’t need a value attribute on a check box because its the browser that decide what value if any to send via the GP headers.

    http://www.w3.org/TR/html401/interact/forms.html

    Checkboxes (and radio buttons) are
    on/off switches that may be toggled by
    the user. A switch is “on” when the
    control element’s checked attribute is
    set. When a form is submitted, only
    “on” checkbox controls can become
    successful.

    So basically if a checkbox is not selected then the entity will not be sent via the headers, there for isset() would be a perfectly usable check.

    The way your using real escape is totally wrong, you should never user real escape for html, DATABASE ONLY.

    Take this code for example

    if(isset($_POST['some_check']))
    {
        echo $_POST['some_check']; //on
    }else
    {
        echo 'some_check has not been checked';
    }
    

    Your code:

    if (isset($_POST['ad_approve'])) $ad_approve  = htmlspecialchars(strip_tags(mysql_real_escape_string($_POST['ad_approve'])));
            else { $ad_approve = 0; }
    

    Can you give me a good excuse why your using htmlspecialchars,strip_tags and mysql_real_escape_string on an entity that can be done like so:

    $ad_approve = isset($_POST['ad_approve']) ? true : false;
    

    for issues like this its not that hard to refer to the documentation to get a better understand of what exactly is being sent from the browser.

    if you wish to add values to to the checkboxes that you would do this with hidden fields, example follows.

    <input type="checkbox" name="check_box" />
    <input type="hidden" name="check_box_value" value="01100001" />
    

    And within the php server side.

    if(isset($_POST['check_box']))
    {
        echo $_POST['check_box_value']; //01100001
    }else
    {
        echo 'some_check has not been checked';
    }
    

    by adding another html input thats hidden you can hide elements from the user and then use as data holders, the reason why you should use the exact same name but append it with _value is just for best practises.


    EDIT

    if(isset($_POST['some_check_box']))
    {
        mysql_query('UPDATE profile SET receive_mail = 1');
    }else
    {
       mysql_query('UPDATE profile SET receive_mail = 0');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make http form post using NSURLConnection in iOS. I have two
I have two forms. The first form is the mainForm, this never goes anywhere.
I have two forms. First one is to decide button numbers by using jslider.
<form action=here.php method=POST> <input type=text name=text> <div id=one> <input type=hidden name=aaa value=one> <input type=submit
I have two forms named form1 and form2 in a php page. I have
I have two forms, first form contains the textbox and second form contains a
I have a form set up and working nearly perfectly. I am using the
I have two forms here. Registration and Payment . In the registration form i
I have two forms in a page. Have decided to update my post with
I am trying to write a dynamic form using PHP. I'd like to have

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.