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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:05:50+00:00 2026-06-10T14:05:50+00:00

I have this code which permits me to insert some dates i’ve selected in

  • 0

I have this code which permits me to insert some dates i’ve selected in a database, now this one inserts just one value, not all, it’s like it stops at the first value..

Could you please tell me what i’m doing wrong?

Thanks!

$job_id=$_REQUEST['job_id'];

$dates = explode(",", $_POST['altField']);
foreach($dates as $date){
$sql="INSERT INTO date (job_id,date) VALUES('$job_id','$date')";
mysql_query($sql);
}
  • 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-10T14:05:52+00:00Added an answer on June 10, 2026 at 2:05 pm
    $job_id=$_REQUEST['job_id'];
    
    $dates = explode(",", $_POST['altField']);
    foreach($dates as $date){
        $values .= '("'.$job_id.'","'.$date.'"),';
    }
    $sql="INSERT INTO date (job_id,date) VALUES " . substr($values, 0, -1);
    mysql_query($sql);
    

    Inserts can have multiple value sets so you just need to set the values in the foreach and then outside of it, do the query. you can also do it this way and get the same result,

    $job_id=$_REQUEST['job_id'];
    
    $dates = explode(",", $_POST['altField']);
    foreach($dates as $date){
        $values[] = '("'.$job_id.'","'.$date.'")';
    }
    $sql="INSERT INTO date (job_id,date) VALUES " . implode(',',$values);
    mysql_query($sql);
    

    REMINDER

    ALWAYS sanitize your inputs. Not doing so could lead to SQL Injections and cause major issues for you. Look at this Also mysql is not maintained and is suggested to switch to MySqli or PDO.

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

Sidebar

Related Questions

I have this piece of code which permits me to print multiple dates, so
i have this piece of code which permits me to insert a title on
i have this quick issue please. I have this code here which permits me
I have this code which retrieves some data from a sql query and place
I have this code here please, which permits me to import data from a
i have this code which permits me to do a request in order to
I have this code which permits me to display all the data in the
I have this code which adds a x number of views to a Multiview
I have this code which does the trick: #include <stdio.h> int main() { int
I have this code which is called at an onChange event of an function

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.