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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:20:10+00:00 2026-06-02T18:20:10+00:00

I have been trying for this but no success. I am using PHP, HTML,

  • 0

I have been trying for this but no success. I am using PHP, HTML, JavaScript, and MySQL. Here is my HTML code:

<div id="Author">
    <LI>Author</LI> 
    <input type = "text" name="Author[]" value = "1. "/>
    <input type="button" value="+" id="Authorbutton" onclick="addAuthor()" />
</div>

If add button is clicked, another textbox will appear and user and put in another name. Here is my JavaScript:

var counter3 = 0;
function addAuthor() {
    // Get the main Div in which all the other divs will be added
    var mainContainer = document.getElementById('Author');

    // Create a new div for holding text and button input elements
    var newDiv = document.createElement('div');

    // Create a new text input
    var newText = document.createElement('input');
    newText.type = "text";
    //var i = 1;
    newText.name = "Author[]";
    newText.value = counter3 + 2 + ". ";

    //Counter starts from 2 since we already have one item
    //newText.class = "input.text";
    // Create a new button input
    var newDelButton = document.createElement('input');
    newDelButton.type = "button";
    newDelButton.value = "-";

    // Append new text input to the newDiv
    newDiv.appendChild(newText);
    // Append new button input to the newDiv
    newDiv.appendChild(newDelButton);
    // Append newDiv input to the mainContainer div
    mainContainer.appendChild(newDiv);
    counter3++;
    //i++;

    // Add a handler to button for deleting the newDiv from the mainContainer
    newDelButton.onclick = function() {
        mainContainer.removeChild(newDiv);
        counter3--;
    }
}

Here is my PHP code:

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($database, $con);



$sql="INSERT INTO savetest (type, number)
VALUES
('$_POST[type]','$_POST[Author]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con);
echo "Thank you for submitting your details!";

I heard a lot of people can get this to work by using arrays, but the data I stored in the database is Array. It does not matter how many textboxes I’ve created, just Array.

Am I using the correct approach? Should I save this array of data in one database fields?

  • 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-02T18:20:11+00:00Added an answer on June 2, 2026 at 6:20 pm
    if (!$con){
       die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db($database, $con);
    
    $authors = $_POST['Author'];
    foreach($authors as $author) :
        $sql="INSERT INTO savetest (type, number) VALUES ('{$_POST['type']}','{$author}')";
    
        if (!mysql_query($sql,$con)){
           die('Error: ' . mysql_error());
        }
    endforeach;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to tackle this problem , but I am having difficulty
I have been trying to solve this problem for a while, but couldn't with
I have been pulling my hair trying to figure this out but nothing is
Okay I been trying to work this out but unable too. I have a
I've been trying to find a way to do this but, have not found
This is a simple htaccess question for experts but I have been trying to
I have been trying this for hours without success. http://replicaisland.googlecode.com/svn/trunk/ I have added the
I'm new here. I have been trying to create a video capture app using
I am sure this has been asked already, but I have been trying all
I've been trying this: NSNumberFormatter *testNumber=[NSNumberFormatter new]; if (![testNumber numberFromString:someNSString]) I have been told

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.