1
/* 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 + '" > ' +
'<input type="text" id="year' + experiencectr +
'" size="5" name="years[]"><label>years</label>');
newTextBoxDiv.appendTo("#ExperienceBoxesGroup");
experiencectr++;
});
在上面的代碼,它增加了兩個領域:經驗和多年文本框Foreach的兩個循環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(); }
}
在上面這段代碼,它保存到數據庫中,但該領域列在所有行相同的值。你們能幫我嗎?
我需要一個答案:d
對不起復制並粘貼第二個代碼,但我得到了一個錯誤:致命錯誤:調用成員函數prepare()在$ stmt = $ dbh-> prepare(「INSERT INTO experience(number,experience,years)VALUES(?,?,?)」 );'。呃我會怎麼做?我',在這裏不是那麼好:) –
YEY!我得到它的工作!謝謝:)我用第一個.. –