$(document).ready(function(){
var skillctr = 1;
var experiencectr = 1;
var educationctr = 1;
var achievementctr = 1;
var historyctr = 1;
/*
Add Skills
*/
$("#addSkill").click(function () {
if(skillctr>10){
alert("WOW! But 10 skills are enough.");
return false;
}
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'SkillDiv' + skillctr);
newTextBoxDiv.html('<label>Skill No. '+ skillctr + ' : </label>' +
'<input type="text" name="skill' + skillctr +
'" id="skill' + skillctr + '" value="" >');
newTextBoxDiv.appendTo("#SkillsBoxesGroup");
ski开发者_StackOverflow中文版llctr++;
});
so how can i save the generated fields in my table in database now? how am i gonna declare the field in php like.. $_POST['skill']. i need help here. please
Don't use name="skill' + skillctr + '"
, use name="skill[]"
.
That way PHP will helpfully create an array that you can loop though:
var_dump($_POST);
foreach ($_POST['skill'] as $skill) {
// save $skill to database
}
You just need to make sure that the input elements you are adding with that javascript are inside a <form>
. Then when you submit the form to a php page, you can access the values with $_POST
like you wrote above.
精彩评论