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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:37:27+00:00 2026-05-25T09:37:27+00:00

/* Adding Experiences */ $(#addExperience).click(function () { if(experiencectr>5){ alert(WOW! But 5 experiences are enough.);

  • 0
    /* Adding Experiences */
$("#addExperience").click(function () {

if(experiencectr>5){
        alert("WOW! But 5 experiences are enough.");
        return false;
}   

var newTextBoxDiv = $(document.createElement('div'))
     .attr("id", 'ExperienceDiv' + experiencectr);

newTextBoxDiv.html('<label>Experience No. '+ experiencectr + ' : </label>' +
      '<input type="text" name="experience[]" id="experience' + experiencectr + '" >&nbsp;' +
      '<input type="text" id="year' + experiencectr +
      '" size="5" name="years[]"><label>years</label>');

newTextBoxDiv.appendTo("#ExperienceBoxesGroup");


experiencectr++;
 });

In the code above, It adds two fields: experience and years textfields

    foreach ($_POST['experience'] as $experience) {
// save $experience to database
$sql_experience = "INSERT INTO experiences(number,experience)
values ('$number','$experience')";
if($result3 = mysql_query($sql_experience ,$db))
    {
            foreach ($_POST['years'] as $years) {
            $sql_years = "UPDATE experiences SET years=$years WHERE experience=$experience";
            if($result = mysql_query($sql_years ,$db))
                { }
            else 
                { echo "ERROR: ".mysql_error(); }
            }
    }
else 
    { echo "ERROR: ".mysql_error(); }
}

In this code above, it saves into database but the field columns have the SAME value in all rows. Can you guys please help me?

I need an answer 😀

  • 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-25T09:37:28+00:00Added an answer on May 25, 2026 at 9:37 am

    You have to get the indexes to access the values in the other array:

    foreach($_POST['experiences'] as $idx => $experience) {
        $sql = "INSERT INTO experiences (number, experience, years)
                VALUES ({$idx}, {$experience}, {$_POST['years'][$idx]}");
        // execute query, etc
    }
    

    This will work, but you probably shouldn’t do it this way because it leaves you open for SQL injections. A better way to do this would be by sanitizing your inputs (eg: mysql_reaL_escape_string or its mysqli equivalent)

    The best way to go would be using prepared statements:

    $stmt = $dbh->prepare("INSERT INTO experiences (number, experience, years) 
                           VALUES (?, ?, ?)");
    
    foreach($_POST['experiences'] as $idx => $experience) {
        // pass values and execute
        $stmt->execute(array($idx, $experience, $_POST['years'][$idx]));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Adding the row one by one in the button click.. (i tried but its
Adding an element to the head of an alist (Associative list) is simple enough:
Adding Exceptional Handling is a good practise, but I have a doubt, In our
Anyone have experience with adding a ReSharper profile to the VS2008 solution and share
Adding source files more than one directory away (e.g. ../../source.cpp or ../../../somewhere_else/source.cpp, vs. just
Adding more than one child to a WPF StatusBar results in poor layout with
Adding functionality to a class can be done by adding a method or by
When adding new properties to classes, I find myself typing the same things over
When adding a DLL as a reference to an ASP.Net project, VS2008 adds several
When adding an EditItemTemplate of some complexity (mulitple fields in one template), and then

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.