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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:18:21+00:00 2026-05-22T02:18:21+00:00

i am trying for ages but can not get this working. So far this

  • 0

i am trying for ages but can not get this working.

So far this is working perfect

<?
                if ($_POST['newhour_start']!=""&&$_POST['newhour_end']!="") 
                {
                    $inserthour = mysql_query("INSERT INTO hour 
                    (hour_start,hour_end,hour_day) VALUES 
                    ('".$_POST['newhour_start']."','".$_POST['newhour_end']."','".$_POST['newhour_day']."')");
                }

?>
    <td colspan="5">
        Start:<input name="newhour_start" type="text" id="newhour_start" > 
        End: <input name="newhour_end" type="text" id="newhour_end" >
        <input name="newhour_day" type="hidden" id="newhour_day" value="Monday" >
    </td>

My question is how can i add another 5 sets of start and end inputs to this code?

I know i can just add another input names, if statements and change their names but i want to learn the proper way.

  • 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-22T02:18:21+00:00Added an answer on May 22, 2026 at 2:18 am

    You use an array.

    So how to use an array? In HTML, you need this:

    Start #1:<input name="newhour_start[]" type="text" /> 
    End #1: <input name="newhour_end[]" type="text"  />
    
    Start #2:<input name="newhour_start[]" type="text" /> 
    End #2: <input name="newhour_end[]" type="text"  />
    
    Start #3:<input name="newhour_start[]" type="text" /> 
    End #3: <input name="newhour_end[]" type="text"  />
    

    And in PHP you need this:

    if(isset($_POST['newhour_start']) && isset($_POST['newhour_end']))
    {
        foreach($_POST['newhour_start'] as $index => $start)
        {
            $hour_start = $start; // now this is the fun part - you CLEAN this string to avoid SQL injection
            $hour_end = $_POST['newhour_end'][$index]; // clean this one too
    
            $insert[] = "('$hour_start', '$hour_end')";
        }
    
        $query = "INSERT INTO table (first_column, secon_column) VALUES ". implode(',', $insert);
    
    }
    

    I didn’t use your table structure in this example, but I think it’s simple enough so that you can learn and modify it.

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

Sidebar

Related Questions

I am trying to get this to work for ages but doesnt seem to
I've been trying for ages to get this to work - but no matter
I've been trying to get this to work for like ages but with no
I've been trying to solve this for ages (3 days) now and I just
Trying to get my css / C# functions to look like this: body {
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
Been trying for ages now and can't work it out. Here's the website http://www.connorhome.com/
I've spent ages on this, all I'm trying to do is extract the title
Possible Spoiler Warning I've spent ages trying to improve this algorithm and work out
I've been trying for ages to get AdMob Ads to appear in my app.

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.