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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:52:47+00:00 2026-06-05T14:52:47+00:00

Currently I have a form that makes use of fields and check boxes. The

  • 0

Currently I have a form that makes use of fields and check boxes. The fields and checkboxes both update the database perfectly:

<?php
 function renderForm($articletitle, $articleorganization, $articledate, $articleurl, $articletags )
 {
 ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="stylized" class="myform">
      <form id="form" name="form" action="" method="post">

. . .

. . .

 if(count($articletags) > 0)
{
 $articletags_string = implode(",", $articletags);
}

 if (isset($_POST['submit']))
 { 
 $articletitle = mysql_real_escape_string(htmlspecialchars($_POST['articletitle']));
 $articleorganization = mysql_real_escape_string(htmlspecialchars($_POST['articleorganization']));
 $articledate = mysql_real_escape_string(htmlspecialchars($_POST['articledate']));
 $articleurl = mysql_real_escape_string(htmlspecialchars($_POST['articleurl']));
 $articletags = implode(',', $_POST['articletags']);

. . .

mysql_query("INSERT articles SET articletitle='$articletitle',   articleorganization='$articleorganization', articledate='$articledate',   articleurl='$articleurl', articletags='$articletags' ")
 or die(mysql_error()); 

 // once saved, redirect to success page
 header("Location:addsuccess.html"); 
 }
 }
 else

{
 renderForm('','','','');
 }
?>

Now, though, I’m wondering if I should have gone with a boolean checkbox instead.

The reason is that I’ve built an edit form as well and it follows the new entry form exactly except that values are already filled in via the MySQL DB.

So, I’m assuming that it would be considerably easier to use boolean, right?

So, instead of using an array, I should give the checkboxes different names, and on the edit.php page I can use something like:

<?php
 function renderForm($id, $articletitle, $articleorganization, $articledate, $articleurl, $articletags)
 {
 ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="stylized" class="myform">
      <form id="form" name="form" action="" method="post">
      <input type="hidden" name="id" value="<?php echo $id; ?>"/>
        <h1>Edit Details for &nbsp; &nbsp;<?php echo $articletitle; ?></h1>
        <fieldset>
          <legend>Article details</legend>
          <div class="row">
            <div class="field"><label>Article Title</label><input type="text" name="articletitle" value="<?php echo $articletitle; ?>"/></div>
          </div>
          <div class="row">
            <div class="field"><label>Article Author </label><input type="text" name="articleorganization" value="<?php echo $articleorganization; ?>"/></div>
            <div class="field"><label>Article Date </label><input type="text" name="articledate" value="<?php echo $articledate; ?>"/></div>
          </div>
          <div class="row">
            <div class="field"><label>Article Url: </label><input type="text" name="articleurl" value="<?php echo $articleurl; ?>"/></div>
          <div class="row">

          <input type="checkbox" name="articletags1" value="checkbox" id="articletags_0" />
          <input type="checkbox" name="articletags2" value="checkbox 2" id="articletags_1" />

          </div>
        </fieldset>
        <footer><input type="submit" name="submit" value="Submit"></footer></form>
    </div>
  </body>
</html>
<?php
 }

 include('settings.php');

 if (isset($_POST['submit']))
 { 
 if (is_numeric($_POST['id']))
 {
 $id = $_POST['id'];
 $articletitle = mysql_real_escape_string(htmlspecialchars($_POST['articletitle']));
 $articleorganization = mysql_real_escape_string(htmlspecialchars($_POST['articleorganization']));
 $articledate = mysql_real_escape_string(htmlspecialchars($_POST['articledate']));
 $articleurl = mysql_real_escape_string(htmlspecialchars($_POST['articleurl']));
 $articletags = implode(',', $_POST['articletags']);


 if ($articletitle == '' || $articletags == '')
 {
 $error = 'ERROR: Please fill in all required fields!';
 renderForm($id, $articletitle, $articletags);
 }
 else
 {
 mysql_query("UPDATE articles SET articletitle='$articletitle', articleorganization='$articleorganization', articledate='$articledate', articleurl='$articleurl', articletags='$articletags' WHERE id=$id")
 or die(mysql_error()); 

 header("Location: editsuccess.html"); 
 }
 }
 else
 {
 echo 'Error!';
 }
 }
 else
 {
 if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
 {
 $id = $_GET['id'];
 $result = mysql_query("SELECT * FROM articles WHERE id=$id")
 or die(mysql_error()); 
 $row = mysql_fetch_array($result);
 if($row)
 {
 $articletitle = $row['articletitle'];
 $articleorganization = $row['articleorganization'];
 $articledate = $row['articledate'];
 $articleurl = $row['articleurl'];
 $articletags = $row['articletags'];

 renderForm($id, $articletitle, $articleorganization, $articledate, $articleurl, $articletags, '');
 }
   else
 {
   echo "No results!";
 }
 }
   else
 {
   echo 'Error!';
    }
     }
?>

The problem with that though is that my checkboxes on the edit.php page still aren’t showing the checked state.

  • 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-05T14:52:49+00:00Added an answer on June 5, 2026 at 2:52 pm

    You need to use checked="checked" in the same way as you used for value. See the solution bottom:

    <input type="checkbox" <?php if(isset($_POST[articletags1])) echo 'checked="checked" ' ?>name="articletags1" value="checkbox" id="articletags_0" />
    <input type="checkbox" <?php if(isset($_POST[articletags2])) echo 'checked="checked" ' ?>name="articletags2" value="checkbox 2" id="articletags_1" />
    

    Hope this works. Updated the right code. Use ini_set('display_errors', 1); to get the error generated.

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

Sidebar

Related Questions

I currently have a PHP form that uses AJAX to connect to MySQL and
I have a form with multiple input fields that use datepicker. I have just
I currently have form that checks if a user has unsubmitted changes when they
I currently have a simple form that when you click the save button will
I currently have a web form aspx page that calls RegisterClientScriptBlock. This sends down
I currently have this useful code that I found elsewhere on StackOverflow: form.DrawToBitmap(bmp, new
I have a Profile form that inherits from sfGuardRegisterForm I have these fields: $this->useFields(
I have a form that I currently enumerate with some Javascript functionality and then
The basics: I have a contact form that uses php to validate the forms.
I have about 20 text fields on a form that a user can fill

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.