3 행이 있습니다. 동적으로 생성 된 것입니다. 을 클릭하면을 추가하면 모두 세 개의 필드가 동적으로 생성됩니다. 제대로 작동하고 있습니다.PHP를 통해 표의 동적 행 삽입
하지만이 필드를 동적으로 mysql 쿼리를 통해 테이블에 삽입하고 싶습니다. 노력했지만 작동하지 않습니다. 누구든지 그것을 해결하도록 도와주세요. 고맙습니다.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
var rowCount = 1;
window.addMoreRows = function(frm) {
rowCount++;
var recRow = '<div id="rowCount' + rowCount + '"><div class="col-sm-3 text-left">College Name:</div><div class = "col-sm-9"><input type="text" name = "collegename[]" placeholder = "College Name" class = "form-control"/></div><div class = "col-sm-3 text-left" > Affiliated University: </div><div class = "col-sm-9" ><input type = "text" name = "univ[]" placeholder = "Affiliated University" class = "form-control"/> </div><div class = "col-sm-3 text-left" > Course Name: </div> <div class = "col-sm-9" ><input type = "text" name = "cname[]" placeholder = "Course Name" class = "form-control"/></div><div class = "col-sm-3 text-left" > Major & Subject: </div><div class = "col-sm-9"><input type = "text" name = "msub[]" placeholder = "Major Subject" class = "form-control"/></div><div class = "col-sm-3 text-left"> Final & Percentage: </div><div class = "col-sm-9"><input type = "text" name = "fper[]" placeholder = "Final Percentage" class = "form-control"/></div><a href = "javascript:void(0);" onclick = "removeRow (' + rowCount + ');" >Delete</a></div> ';
$('#addedRows').append(recRow);
}
window.removeRow = function(removeNum) {
$('#rowCount'+removeNum).remove();
}
</script>
<?php
extract($_POST);
if (isset($_POST['submit_val'])) {
if ($_POST['dynfields']) {
foreach (array_keys($dynfields) as $key) {
$txt = $dynfields[$key];
$txt1 = $univ[$key];
$txt2 = $cname[$key];
$txt3 = $msub[$key];
$txt4 = $fper[$key];
$query = mysql_query("INSERT INTO dynamicfield VALUES ('','','$txt','$txt1','$txt2','$txt3','$txt4')");
}
}
echo "<i><h2><strong>" . count($_POST['dynfields']) . "</strong> Hobbies Added</h2></i>";
mysql_close();
}
?>
<form action="" method="post" id="addedRows">
<h5 align="left"><u style="color:#449D44;">Other Studies</u>-<span style="font:normal 12px agency, arial; color:blue; text-decoration:underline; cursor:pointer;" onclick="addMoreRows(this.form);">Add More Other Studies</span></h5>
<span id="rowId">
<div class="col-sm-3 text-left">College Name: </div>
<div class="col-sm-9"><input type="text" name="dynfields[]" placeholder="College Name" class="form-control" /></div>
<div class="col-sm-3 text-left">Affiliated University: </div>
<div class="col-sm-9"><input type="text" name="univ[]" placeholder="Affiliated University" class="form-control" /></div>
<div class="col-sm-3 text-left">Course Name: </div>
<div class="col-sm-9"><input type="text" name="cname[]" placeholder="Course Name" class="form-control" /></div>
<div class="col-sm-3 text-left">Major Subject: </div>
<div class="col-sm-9"><input type="text" name="msub[]" placeholder="Major Subject" class="form-control" /></div>
<div class="col-sm-3 text-left">Final Percentage: </div>
<div class="col-sm-9"><input type="text" name="fper[]" placeholder="Final Percentage" class="form-control" /></div>
</span>
<input type="submit" name="submit_val" value="Submit" />
당신이 당신의 입력 필드 이름 어디 찾을 수 없습니다
열 이름은 무엇입니까? – C2486
이름, 이메일, 모바일 – user3526766
쿼리에 열 이름을 사용하십시오. 내 ans를 참조하십시오. – C2486