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

  • Home
  • SEARCH
  • 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 6823183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:45:09+00:00 2026-05-26T21:45:09+00:00

I have table with checkboxes, which I retrieve from database : <?php $result =

  • 0

I have table with checkboxes, which I retrieve from database :

<?php
$result = mysql_query("SELECT shop_id, name FROM shop") or die(mysql_error());

if(mysql_num_rows($result) > 0)
{
    while($row = mysql_fetch_assoc($result)) 
    {
        echo '<tr> 
                  <td>
                      <input type="checkbox" name="identifer[]" value="'.$row['shop_id'].'" /> <br />
                  </td>  
                  <td>'.ucfirst($row['shop']).'</td> 
              </tr>   ';    
     }
}
?>

I want to save the results in database:

  • Table: places
  • Columns: places_id, book_id, shop_id

However, I can’t get it to work right. In shop_id column I get the same number as many times as checkboxes are checked.

If I’m using this:

$identifer = $_POST['identifer'];
if( count( $identifer) > 1)
{
    foreach($identifer as $x)
    {
        $y .= $x.",";
        $val = rtrim($y,",");
        $q2 = "INSERT INTO places (places_id, book_id, shop_id) VALUES (NULL, '$book_id', '$val')";
        $result2 = mysql_query($q2) or die(mysql_query());
    }
}

In places table I get just one row no matter how many times checkboxes are checked.

So what is the correct way to do that?

  • 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-26T21:45:09+00:00Added an answer on May 26, 2026 at 9:45 pm

    I think this is what you’re looking for:

    $identifier = $_POST['identifer']; // Also, you spelled identifier wrong ;)
    // There's no guarantee that you were given an array for identifier
    if( is_array( $identifier) && count( $identifier) > 1)
    {
        $values = array();
        // This creates a bunch of insert values
        foreach($identifier as $x)
        {
            $values[] = "(NULL, '$book_id', '$x')";
        }
    
        // Join all those values together into one SQL query (this will generate multiple rows)
        $q2 = "INSERT INTO places (places_id, book_id, shop_id) VALUES " . implode( ', ', $values);
        $result2 = mysql_query($q2) or die(mysql_query());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently we have a table with a bunch of data from a database which
I'm currently dynamically building an asp:table which contains checkboxes these checkboxes have a CheckChanged
I have a collection of checkboxes loaded from a table that are loaded in
i have database table with few text fields which i use to filter data
I have a gridview which contains checkboxes and fields in sql server database which
I have a matrix of checkboxes which I am laying out in a table.
I have a table that displays from db all infrastructures (their name, description, performance).
I have a table with multiple rows which contain form inputs (checkboxes, text, dropdowns).
I have a table of todos and on the leftmost column are normally checkboxes
I have table with 50 entries (users with such details like Name Surname Location

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.