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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:39:58+00:00 2026-05-26T03:39:58+00:00

I have a while statement that’s executing correctly but it needs to be a

  • 0

I have a while statement that’s executing correctly but it needs to be a foreach statement since there are multiple inserts being made and it’s not generating the random password or sending the email for each. Here’s the code:

        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
     {

        $password = createRandomPassword(); 

        // Add the user to the database:
        $sql = "INSERT into users(account_id,first,last,email,pass) values('$id', '$data[0]','$data[1]','$data[2]','$password')";
        $r = mysqli_query ($dbc, $sql) or trigger_error("Query: $sql\n<br />MySQL Error: " . mysqli_error($dbc));


            if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

                    $emailBody = "<html><body>";

                    $emailBody .= "<br><br><b>Hey $first $last!</b>";

                    $emailBody .= "<br><br>You've been added to our site and your password is: $password";

                    $emailBody .= "</body></html>";

                    mail("$ln_first $ln_last <$ln_email>", "Your Account" , $emailBody, "From: YourCompany <noreply@yourcompany.com>\nContent-Type: text/html");

            }

     fclose($handle);
    echo '<p><div class="alert green">You have successfully imported users.</div></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-26T03:39:59+00:00Added an answer on May 26, 2026 at 3:39 am

    I don’t think there’s anything wrong with your while loop – you’re closing the handle too early! The fclose and final echo lines should be after that final curly bracket.

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

Sidebar

Related Questions

I have this SQL statement that works but takes a while to execute I
Given that Groovy does not have a do-while statement, how can I iterate over
I have an if/else statement that is not working. while (rdr.Read()) { string permission
I have a while statement that is echoing about 10 different stories. Every story
What I want to do is have a while statement which loops whilst the
I have some codes read the query results from sqlite: while (sqlite3_step(statement) == SQLITE_ROW)
I have read that while plug-ins are not supported for SQL Server Management Studio,
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
I have two simple while loops in my program that I feel ought to
Problem that i face: -I have an input string, a SQL statement that i

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.