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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:11:46+00:00 2026-05-16T15:11:46+00:00

first off I am a rookie so please forgive my basic question. I am

  • 0

first off I am a rookie so please forgive my basic question. I am trying to use an html checkbox to let me know when to check a serial number. The problem is no matter what i do I get an error telling me “Notice: Undefined index: sncheck in XYZ”.

I tried using a ternary operator to set the value as it was posted (If the checkbox was not checked) but it still fails on me. Any suggestions would be

Here is the code, below im using a checkbox with the name sncheck and a value of ok. thanks!

if (isset($_POST['submit'])){
    $gov = mysqli_real_escape_string( $dbc, trim($_POST['gov']));
    $pctype = mysqli_real_escape_string( $dbc, trim($_POST['pctype']));
    $compname = mysqli_real_escape_string( $dbc, trim($_POST['compname']));
    $username = mysqli_real_escape_string( $dbc, trim($_POST['username']));
    $compmodel = mysqli_real_escape_string( $dbc, trim($_POST['compmodel']));
    $serialnumber = mysqli_real_escape_string( $dbc, trim($_POST['serialnumber']));
    $sncheck = ($_POST['sncheck']== 'ok') ? $_POST['sncheck'] : '';
    $purchdate = mysqli_real_escape_string( $dbc, trim($_POST['purchasedate']));
    $os = mysqli_real_escape_string( $dbc, trim($_POST['os']));
    $memory = mysqli_real_escape_string( $dbc, trim($_POST['memory']));
    $monitor1 = mysqli_real_escape_string( $dbc, trim($_POST['monitor1']));
    $monitor2 = mysqli_real_escape_string( $dbc, trim($_POST['monitor2']));
    $warranty = mysqli_real_escape_string( $dbc, trim($_POST['warranty']));
    $warrantyend = mysqli_real_escape_string( $dbc, trim($_POST['warrantyend']));
    $status = mysqli_real_escape_string( $dbc, trim($_POST['status']));
    $notes = mysqli_real_escape_string( $dbc, trim($_POST['notes']));

    if (dateformat($purchdate) == 1 && $sncheck == "ok"){
            $querysn = "SELECT serialnumber FROM inventory" . 
                                " WHERE serialnumber = '" . $serialnumber . "'";
            $data = mysqli_query($dbc, $querysn) or die('Error querying the Database for Serial Numbers');
            if (mysqli_num_rows($data) == 0){
                $queryupdate = "UPDATE inventory SET government = '$gov', pctype = '$pctype', compname = '$compname'," . 
                                    " username = '$username', compmodel = '$compmodel', serialnumber = '$serialnumber', purchased = '$purchdate'," . 
                                    " operatingsystem = '$os', `memory` = '$memory', monitor1 = '$monitor1'," . 
                                    " monitor2 = '$monitor2', warranty = '$warranty', warrantyend = '$warrantyend', `status` = '$status', notes = '$notes'" . 
                                    " WHERE serialnumber = '" . $_POST['serialnumber'] . "'";
                mysqli_query($dbc, $queryupdate);
                echo 'PC was sucessfully saved';
            }
            else{
                echo '<p class="error">The serial number has already been used, please try another</p>';
            }
    }
    else{
        echo '<p class="error">The date format does not match</p>';
    }

    if (dateformat($purchdate) == 1){
            $querysn = "SELECT serialnumber FROM inventory" . 
                                " WHERE serialnumber = '" . $serialnumber . "'";
            $data = mysqli_query($dbc, $querysn) or die('Error querying the Database for Serial Numbers');
            if (mysqli_num_rows($data) == 0){
                $queryupdate = "UPDATE inventory SET government = '$gov', pctype = '$pctype', compname = '$compname'," . 
                                    " username = '$username', compmodel = '$compmodel', purchased = '$purchdate'," . 
                                    " operatingsystem = '$os', `memory` = '$memory', monitor1 = '$monitor1'," . 
                                    " monitor2 = '$monitor2', warranty = '$warranty', warrantyend = '$warrantyend', `status` = '$status', notes = '$notes'" . 
                                    " WHERE serialnumber = '" . $_POST['serialnumber'] . "'";
                mysqli_query($dbc, $queryupdate);
                echo 'PC was sucessfully saved';
            }
            else{
                echo '<p class="error">The serial number has already been used, please try another</p>';
            }
    }
    else{
        echo '<p class="error">The date format does not match</p>';
    }
}
  • 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-16T15:11:46+00:00Added an answer on May 16, 2026 at 3:11 pm

    EDITED ANSWER: Based on your edited question, try changing:

    $sncheck = ($_POST['sncheck']== 'ok') ? $_POST['sncheck'] : '';
    

    to:

    $sncheck = isset($_POST['sncheck']);
    

    If a checkbox is checked, it will be set in $_POST. If it’s not checked it will not be.

    ORIGINAL ANSWER:

    It’s tough to answer your question without seeing code, so I’m just stabbing in the dark, but here goes. Here’s an example:

    <?php
    
    $serial_numbers = array('1','2','3'); // Put your real serial numbers here...
    
    if(isset($_REQUEST['submit']))
    {
        if(isset($_REQUEST['serial_numbers']) && is_array($_REQUEST['serial_numbers']))
        {
            foreach($_REQUEST['serial_numbers'] as $serial)
            {
                // Do something with this serial number
                echo "You checked $serial<br>";
            }
        }
    }
    else
    {
        // Show a form to select serial numbers:
    
        echo "<form action=\"$PHP_SELF\">";
        foreach($serial_numbers as $serial)
        {
            $serial_ht = htmlspecialchars($serial);
            echo "<input type=\"checkbox\" name=\"serial_numbers[]\" value=\"$serial_ht\">$serial_ht<br>";
        }
    
        echo '<input type="submit" name="submit" value="Submit">';
    }
    

    This is a complete guess because I’m not sure what you’re doing. But this will take an array of serial numbers and display a form containing them all with checkboxes next to each one. When the form is submitted, the selected serial numbers will be in $_REQUEST['serial_numbers'] (which will be an array). The script will loop through each member of this array and print those serial numbers back. Not very useful, but again, it’s just an example. Please post some code if you’d like more direction and I’ll edit my answer.

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

Sidebar

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.