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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:18:18+00:00 2026-05-11T19:18:18+00:00

I have a very simple PHP form, which shows a checkbox, and will store

  • 0

I have a very simple PHP form, which shows a checkbox, and will store if it is checked or not in a database. This works for the initial inserting, but not for updating. I have tested cases where $saleid equals $pk and it does not enter the if branch to update…why?

<?php
error_reporting(E_ALL);

if (isset($_GET["cmd"]))
  $cmd = $_GET["cmd"]; 
    else
if (isset($_POST["cmd"]))
  $cmd = $_POST["cmd"]; 
        else die("Invalid URL");

if (isset($_GET["pk"])) { $pk = $_GET["pk"]; }

$checkfield = "";

$checkboxes = (isset($_POST['checkboxes'])? $_POST['checkboxes'] : array());

if (in_array('field', $checkboxes)) $checkfield = 'checked';

$con = mysqli_connect("localhost","user","", "db");
if (!$con) { echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error(); exit; }

$con->set_charset("utf8");

$getformdata = $con->query("select saleid, field from STATUS where saleid = '$pk'");
$saleid = "";
while ($row = mysqli_fetch_assoc($getformdata)) {
    $saleid = $row['saleid'];
    $checkfield = $row['field'];
}

if($cmd=="submitinfo") {
    if ($saleid == null) {
       $statusQuery = "INSERT INTO STATUS VALUES (?, ?)";
        if ($statusInfo = $con->prepare($statusQuery)) {
                $statusInfo->bind_param("sssssssssssss", $pk, $checkfield);
                $statusInfo->execute();
                $statusInfo->close();
        } else {
                print_r($con->error);
        }
    } else if ($saleid == $pk) {
        $blah = "what";
        $statusQuery = "UPDATE STATUS SET field = ? WHERE saleid = ?";
        if ($statusInfo = $con->prepare($statusQuery)) {
                $statusInfo->bind_param("ss", $checkfield, $pk);
                $statusInfo->execute();
                $statusInfo->close();
        } else {
                print_r($con->error);
     }  
    }
}
if($cmd=="EditStatusData") {
    echo "<form name=\"statusForm\" action=\"test.php?pk=".$pk."\" method=\"post\" enctype=\"multipart/form-data\">
                <h1>Editing information for Auction No: ".$pk."</h1>
                        <input type=\"checkbox\" name=\"checkboxes[]\" value=\"field\" ".$checkfield." />
                        <label for=\"field\">Test</label>
                        <br />
                        <input type=\"hidden\" name=\"cmd\" value=\"submitinfo\" />
                        <input name=\"Submit\" type=\"submit\" value=\"submit\" />
        </form>";
}
?>
  • 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-11T19:18:18+00:00Added an answer on May 11, 2026 at 7:18 pm

    well i created a table and ran your code and it works fine for me

    the reason why it doesn’t “look” like update is working, is because you are reading
    $saleid and $checkfield from the database then building an update statement that puts the same two values back into the database

    which probably isn’t what you are wanting to do

    this line here sets $checkfield to ‘checked’,

     if (in_array('field', $checkboxes)) $checkfield = 'checked';
    

    then you set $checkfield from the database (overwriting the value ‘checked’ )

    while ($row = mysqli_fetch_assoc($getformdata)) {
       $saleid = $row['saleid'];
       $checkfield = $row['field'];
    

    then you write the original value of checkfield back to the database

    $statusInfo->bind_param("ss", $checkfield, $pk);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple PHP script which creates favicon.ico form jpg/gif/png uploaded file.
I have written a very very very simple!! script in php. header redirection not
I have a PHP form that needs some very simple validation on submit. I'd
I have a very simple chat system I've built using PHP and MySQL (this
I have this html form which calls a php file . The index.html ->
I have this very simple login form with user and pass and I need
I have very simple form that gets values in JSON format from searchAlbum.php .
I have a very simple test page for PHP session. <?php session_start(); if (isset($_SESSIONS['views']))
I have the following PHP code doing a very simple select into a table.
I have very simple select like this: SELECT * FROM table WHERE column1 IN

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.