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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:26:57+00:00 2026-06-04T02:26:57+00:00

I am trying to get multiple rows to insert into a mysql table from

  • 0

I am trying to get multiple rows to insert into a mysql table from a form that allows for multiple checkboxes.

This is the form:

<input type='submit' name='invite-group' value='Invite To Group'>
<br />
<?php
$query2aac = mysql_query("SELECT * FROM follow WHERE yoozer1='$userdb1a' AND  followaccept='Yes' ORDER BY yoozer2 DESC");

while($row2aac = mysql_fetch_array($query2aac))
{
    $rowid = $row2aac['followid'];
    $yoozer2aac = $row2aac['yoozer2'];
    $yoozer2aacurl = strtolower($yoozer2aac);
    $palurl = '<a href="http://www.bunchofus.com/fanpage/' . $yoozer2aacurl . '">' .    $yoozer2aac . '</a>';
    echo '<input type= "hidden" name = "id[]" value="' . $rowid . '"></input>';
    echo '<input type= "checkbox" name = "friends[]" value="' . $yoozer2aac . '">' . $palurl . '</input><br />';
}   
?>

This is the php:

if ($submit)
{
    $submit = $_POST['invite-group'];
    $date1 = date("Y-m-d");
    $lowername = strtolower($username);
    $combined = $_POST['friends'];

    foreach ($combined as $username) 
    {
        $insert1 = mysql_query("INSERT INTO grprequest VALUES ('','$grpid3','$username','$myuser','$grprights3','$grpactive3')");
    }
}
?>

It is inserting one line into the database but not multiple lines. If I echo the username after the foreach, multiple usernames are showing.

If anyone could help I would appreciate it.

  • 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-04T02:26:59+00:00Added an answer on June 4, 2026 at 2:26 am

    Based on the sample code you’ve provided, and the var_dump of $combined, I’m not sure why it isn’t working for you. But perhaps you could try something like this:

    $inserts = array();
    foreach ($combined as $username)
        $inserts[] = "('','$grpid3','$username','$myuser','$grprights3','$grpactive3')";
    
    $query = "INSERT INTO grprequest VALUES ". implode(", ", $inserts);
    
    echo "query = $query"; // for debugging purposes, remove this once it is working
    mysql_query($query) or die(mysql_error());
    

    This will perform all of your inserts in one call to the database. I added an echo before performing the query so that you can see the exact query that’s being performed.


    One thing that you should definitely note is that it looks like your code is vulnerable to SQL injection. There are hundreds of places you can look to find out more about how to protect yourself, so just search for it. My favorite reference is Bobby Tables.

    It also looks like your form is vulnerable to XSS attacks. You select data from the database and insert it directly into HTML, but you should sanitize it first (using something like htmlspecialchars).

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

Sidebar

Related Questions

I am trying to insert multiple rows in a MySQL table from PHP arrays.
I'm trying to get results from a MySQL database (for invoices) that includes multiple
I'm trying to generate a sequence table in MySQL, so that I can get
I have a tricky situation in trying to get information from multiple queries into
I am trying to insert 2 rows into the same table. The first will
I am trying to select some fields from one table and insert them into
I'm trying to grab multiple rows via these lines from the MySQL database: $msg_sql
I am trying to get my query to grab multiple rows while returning the
I'm trying to select multiple rows over different tables but I can't get it
Using SQL Server 10.0 and 10.5 I'm trying to fetch multiple rows into one

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.