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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:30:27+00:00 2026-05-13T05:30:27+00:00

I need help. What seems to be the problem with our php codes? We

  • 0

I need help. What seems to be the problem with our php codes? We can’t seem to insert our data into our database. I’m just a beginner and I’m tasked to store multiple data into multiple arrays into our database. What we’re actually doing is to enter a number (ex: 5) and 5 forms should show within that page. each form would consist of name address and tel phone number. after that we submit it to our database. We have already controlled hot many forms to show but we weren’t able to store the data inserted. Can anyone help us please? Thank you.

form.php

<form method="POST" action="form.php">
<input type="text" name="waw" />
<input type="submit" />

<?php 
$i=0;

while ($i<$_POST['waw'])
{
?>
</form>

<form method="POST" action="input.php">
<!-- Person #1 -->

<input type="text" name="username[]" />

<input type="text" name="phonenum[]" />

<input type="text" name="add[]" />


<?php 
$i++;
}
?>
<input type="submit" />
</form>

input.php

<?php

$username="maizakath";
$password="12345";
$database="tryinsert";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("<b>Unable to specified database</b>");



$sql_start = 'INSERT INTO `mytable` VALUES '; 
$sql_array = array(); 
$queue_num = $_POST['waw']; 
foreach ($_POST['username'] as $row=>$name)
{
$username = $name;
$phonenum = $_POST['phonenum'][$row];
$add = $_POST['add'][$row];
$sql_array[] = '(' . $username . ', ' . $phonenum . ', ' . $add . ')'; 
if (count($sql_array) >= $queue_num)
{ 
mysql_query($sql_start . implode(', ', $sql_array)); 
$sql_array = array(); 
}
}
if (count($sql_array) > 0) 
{
mysql_query($sql_start . implode(', ', $sql_array))or die(mysql_error());
} 


?>
  • 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-13T05:30:27+00:00Added an answer on May 13, 2026 at 5:30 am

    I’ve modified your code to make it work:

    form.php

    <form method="POST" action="form.php">
    <input type="text" name="waw" />
    <input type="submit" />
    </form>
    
    <form method="POST" action="input.php">
    <?php 
    $i=0;
    
    while ($i<$_GET['waw'])
    {
    ?>
    
    <!-- Person #1 -->
    
    <input type="text" name="username[]" />
    
    <input type="text" name="phonenum[]" />
    
    <input type="text" name="add[]" /><br />
    
    
    <?php 
    $i++;
    }
    ?>
    <input type="submit" />
    </form>
    

    input.php

    <?php
    
    
    $username="maizakath";
    $password="12345";
    $database="tryinsert";
    mysql_connect('localhost',$username,$password);
    @mysql_select_db($database) or die("<b>Unable to specified database</b>");
    
    
    
    $sql_start = 'INSERT INTO `mytable` VALUES '; 
    $sql_array = array(); 
    $queue_num = $_POST['waw']; 
    foreach ($_POST['username'] as $row=>$name)
    {
    $username = $name;
    $phonenum = $_POST['phonenum'][$row];
    $add = $_POST['add'][$row];
    $sql_array[] = '("' . $username . '", "'.$phonenum.'", "'.$add.'")'; 
    if (count($sql_array) >= $queue_num) {
      $query_single=$sql_start . implode(', ', $sql_array);
      mysql_query($query_single); 
      $sql_array = array(); 
    }
    }
    
    if (count($sql_array) > 0)  {
      $query = $sql_start . implode(', ', $sql_array);
      mysql_query($query)or die(mysql_error());
    }
    
    ?>
    

    It works fine. I’ve just tested it on my local machine.

    EDIT(Comments):

    1. Usage of variable $queue_num in input.php is senseless, because this variable is available only in form.php script(‘wow’ input placed in another form, which is submitted to file form.php, not input.php). So if (count($sql_array) >= $queue_num) block works wrong;

    2. Check your config settings for the database connection(as I’ve wrote in comment, you have to define constant with name ‘localhost’ or enclose word localhost with quotes);

    3. I’ve modified your form, because it had wrong structure;

    4. I didn’t understand the objective of creating first form in form.php.

    You can modify this code to make it more appropriate for your case. But firsat of all try to use this one.

    Note. Use var_dump() function to see your $_POST array during debugging to understand, what variables are available.

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

Sidebar

Related Questions

Seems like i need some help with a project. I have a routine ,
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
Need help writing a script downloads data from google insight using c# this is
need help in error in database pivot. i have table tamed table_score like below:
I am faced with a unique problem and probably need some external help and
I've been at this all day and I just can't seem to figure it
I really need help getting this query right. I can't share actual table and
Seems like a simple problem: I have an SVN repo inside our firewall. I
I need help with the Pythonic looping overhead of the following problem: I'm writing
Good morning, everyone. I need some query help. You can assume I understand relatively

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.