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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:26:55+00:00 2026-06-14T10:26:55+00:00

I want to insert N number of rows in a mysql table called USERS.

  • 0

I want to insert N number of rows in a mysql table called USERS. For inserting a single row I write this code (it works):

PHP side: insert_user.php

<?php   
    $mysqli = new mysqli('hostname', 'username','password', 'dbname');
    if (mysqli_connect_errno()) {
       printf("Can't connect Errorcode: %s\n", mysqli_connect_error());
       exit;
    }

    if ($result = $mysqli->prepare("INSERT INTO `users` (`email`, `imei`) VALUES (?,?)")) {
        $email = $_POST['email'];
        $imei = $_POST['imei'];

        $result->bind_param("ss", $email, $imei);
        $result->execute();
        $result->close();
        printf("Insert OK");
    } else {
        printf("Insert KO. ERROR: %s",mysqli_error());
    }

    $mysqli->close();     
?>

JAVA side

public void insertUser(String email
             , String imei) {

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("email", email));
    nameValuePairs.add(new BasicNameValuePair("imei", imei));

    // send them on their way
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("myserver.com/insert_user.php");
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse httpResponse = httpClient.execute(httpPost);
    } catch (e) {
        e.printStackTrace();
    }

}

THE QUESTION

I need a little complete example for “insert_multi_user.php” and the relative java method, to pass more rows (using an Array? a Collection? I don’t know…).
For instance, replacing this java lines:

    nameValuePairs.add(new BasicNameValuePair("email", email));
    nameValuePairs.add(new BasicNameValuePair("imei", imei));

with arrays (?):

    nameValuePairs.add(new BasicNameValuePair("email", email[]));
    nameValuePairs.add(new BasicNameValuePair("imei", imei[]));

and, in php, replacing:

    $email = $_POST['email'];
    $imei = $_POST['imei'];

with:

    $email[] = $_POST['email'];
    $imei[] = $_POST['imei'];

(obviously the above code is only to give you the idea, it is not correct…)

I spent days with no luck 🙁
Thank you,
Geltry

  • 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-14T10:26:56+00:00Added an answer on June 14, 2026 at 10:26 am

    Just wrap your code with for loop

    If you have a record/array with users you can do something like

    $users = array(...);
    foreach($users as $user) {
        $mysqli->prepare("INSERT INTO `users` (`email`, `imei`) VALUES (?,?)")l
        $result->bind_param("ss", $user['email'], $user['imei']);
        $result->execute();
        $result->close();
    }
    

    But to do that you have to change the way you submit your data, so don’t do it one by one rather submit a CSV file for example, parse it with fgetcsv and run through each of the records.

    On the Java side you can also pass a POST array:

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
    nameValuePairs.add(new BasicNameValuePair("user[0][email]","email1"));  
    nameValuePairs.add(new BasicNameValuePair("user[0][imei]","imei1"));  
    nameValuePairs.add(new BasicNameValuePair("user[1][email]","email2"));  
    nameValuePairs.add(new BasicNameValuePair("user[1][imei]","imei2")); 
    

    The other options is to send the data in JSON format to the PHP script and use json_decode

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

Sidebar

Related Questions

In my MySql table I want to insert a number of rows. Some of
I want to insert mutiple rows in mysql table using php. Data is in
I want to insert a LARGE number of rows like this: INSERT INTO All
I want to insert a row number in a records like counting rows in
I want to insert a record into a MySQL database table from a formulaire.
I have a SQL query where I want to insert multiple rows in single
I want to insert couple of hundred rows into a table that points to
I have a MySQL table which contains a number of products. What I want
I have a number of rows from a database which I want to insert
I am currently using this php code to count the number of the users

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.