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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:01:37+00:00 2026-05-23T08:01:37+00:00

An array creates by this: <input type=checkbox name=transport[] value=0>Taxi <input type=checkbox name=transport[] value=1>Bus <input

  • 0

An array creates by this:

<input type="checkbox" name="transport[]" value="0">Taxi
<input type="checkbox" name="transport[]" value="1">Bus
<input type="checkbox" name="transport[]" value="2">Train

Although the checkbox only comes if its true(if its checked), so only the checked checkboxes will be passed.

Now I am trying to do so that the checkboxes that gets passed(the ones that are checked), should insert a row in table transports and the checkboxes that are not checked(not gets passed) should delete. And if it already is inserted, it should not do anything.

So:

  • Check if its already inserted before
  • Insert new row in transports
    for the checkboxes passed
  • Delete the
    rows for the checkboxes that didnt
    pass

I tried doing this:

    $transport = $_POST["transport"]; // variable receiving

    for($u=0; $u<3; $u++){ // taxi, bus and train (3)
         if($u == $transport[$u]){ 
            $alreadyExists = $connect->prepare("SELECT id FROM transport WHERE xID=:xID AND transport=:t");
            $alreadyExists->bindValue(":t", $u);
            $alreadyExists->bindValue(":xID", $cID);
            $alreadyExists->execute();
            $alreadyExists = $alreadyExists->rowCount();
            if($alreadyExists == 0){ // if it doesnt exists, insert into
          $updateTransport = "INSERT INTO transport (xID, transport) VALUES (:id, :t)";
          $updateTransport = $connect->prepare($updateTransport);
          $updateTransport->bindValue(":id", $cID);
          $updateTransport->bindValue(":t", $u);
          $updateTransport->execute();
            }
         }else{ // delete row as it is not checked
          $updateTransport = "DELETE FROM transport WHERE xID=:id AND transport=:t";
          $updateTransport = $connect->prepare($updateTransport);
          $updateTransport->bindValue(":id", $cID);
          $updateTransport->bindValue(":t", $u);
          $updateTransport->execute();
         }
    }

But It wont work properly, I receive undefined offset 2, 1 I cant figure out why

What have I done wrong? How can I make it work properly?

  • 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-23T08:01:38+00:00Added an answer on May 23, 2026 at 8:01 am

    you should do somethign like:

    <input type="checkbox" name="transport[tax]" value="1">Taxi
    <input type="checkbox" name="transport[bus]" value="1">Bus
    <input type="checkbox" name="transport[train]" value="1">Train
    

    and

    $toDelete = array('taxi'=>true,'bus'=>true,'train'=>true);  
    foreach($_POST['transport'] as $k=>$v) {
      //> Insert $k
    
      $toDelete[$k]  = false;
    }
    
    foreach($toDelete as $k=>$v) {
       if ($v===true) {
        //> delete $k here
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code here: <?php while($rowequipment = mysql_fetch_assoc($sqlequipment)) { echo '<input type=checkbox name=equipment[]
Say I have the following checkbox: <input type=checkbox value=1-25 /> To get the two
this program accepts user input and saved to a char array. Then creates a
<input type=checkbox name=SummaryInformation>Summary Information<br /> <input type=checkbox name=ProductLegs>Product Legs<br /> <input type=checkbox name=AmortizationOptions>Amortization Options<br
I have this line of code: echo $form->input('type', array('label' => 'Phase', 'type' => 'select',
postgres has an array data type, in this case a numeric array: CREATE TABLE
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
I have an array created with this code: var widthRange = new Array(); widthRange[46]
I create array: TextBox[] textarray = new TextBox[100]; Then in cycle set this params,
Imagine that I want to create an array from another array like this: $array

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.