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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:34:16+00:00 2026-06-12T13:34:16+00:00

I have four texts fields in my form that i need them to be

  • 0

I have four texts fields in my form that i need them to be inserted into my database,but the four fields are optional to either they should all be filled or just part of them,my problem is that in case the user just fills the two fields and leaves the other two empty,then the filled data should be inserted into mysql and the other blank fields should not be inserted.

This is what i have.

Artist:<input type="text" name="artist" />

Artist:<input type="text" name="artist1" />

Artist:<input type="text" name="artist2" />

Artist:<input type="text" name="artist3" />

//my php code

$sql="INSERT INTO artists (name) VALUES ('$artist'),('$artist1'),('$artist2'),('$artist3')";
mysql_query($sql);

but whenever i run this query it inserts all the four fields.Any help please.
And is it relevant to use artist,artist1,artist2,artist3 in the four artist fields or i can just use maybe artist[] for the name part of all the four artist’s fields i have?

  • 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-12T13:34:17+00:00Added an answer on June 12, 2026 at 1:34 pm

    Rename your inputs to have name="artist[]". Not strictly necessary, but much easier.

    Artist:<input type="text" name="artist[]" />
    Artist:<input type="text" name="artist[]" />
    Artist:<input type="text" name="artist[]" />
    Artist:<input type="text" name="artist[]" />
    

    Then process them and build your query as necessary:

    $rawArtists = (isset($_POST['artist']) && is_array($_POST['artist'])) ? $_POST['artist'] : array();
    
    $artists = array();
    
    foreach ($rawArtists as $artist) {
        if (is_string($artist) && strlen($artist)) {
            $artists[] = $artist;
        }
    }
    
    if (count($artists)) {
    
        //This could easily be a loop...  
        //I just enjoy abusing lambdas from time to time :)
        $artistVals = array_map(function ($art) {
            return "('" . mysql_real_escape_string($art) . "')";
        }, $artists);
    
        $vals = implode(',', $artistVals);
    
        $query = "INSERT INTO artists (name) VALUES $vals";
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four email fields in a form, and I want that the user
I have four tables. Three of them are tables with one key and they
i have a small form with four EditText fields in which second EditText is
I do have a credit card number form. The number is divided into four
I have an admin form I'm creating that has four different areas with similar
I have a form with four fields. I have applied some unobtrusive validations to
I have 4 text fields horizontally. Each textFiled will allow only four characters. If
I have a text file that stores combinations of four numbers in the following
i have four tables user-question contains two columns: questionID, userID, the questions that the
i have four imageviews in a linear layout in such a manner that only

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.