2
我在這裏有我的JS腳本,當用戶單擊按鈕'添加項目'時動態添加三個文本框。三個文本框保存在數據庫中時有不同的字段。但似乎在我的PHP代碼中,它並沒有從文本框中捕獲任何值。在數據庫中它只顯示'數組'。請幫幫我!謝謝!如何使用PHP將動態文本框保存到數據庫
<script language="javascript">
row_no=0;
function addRow(tbl,row){
row_no++;
if (row_no<=20){
if (row_no<=20){
if (row_no>=10){
var textbox = row_no+'.) <input type="text" size = "50" maxlength= "50" name= "desk_user[]">';}
if (row_no<10){
var textbox = row_no+'. ) <input type="text" size = "20" maxlength= "50" name= "desk_user[]">';}
var textbox2 = '<input type="text" size = "60" maxlength= "250" name= "desk_report[]">';
var textbox3 = '<input type="text" size = "60" maxlength= "250" name= "desk_action[]">';
var tbl = document.getElementById(tbl);
var rowIndex = document.getElementById(row).value;
var newRow = tbl.insertRow(row_no);
var newCell = newRow.insertCell(0);
newCell.innerHTML = textbox;
var newCell = newRow.insertCell(1);
newCell.innerHTML = textbox2;
var newCell = newRow.insertCell(2);
newCell.innerHTML = textbox3;
}
if (row_no>20){
alert ("Too Many Items. Limit of 20.");
}
}
}
</script>
我的PHP代碼:
<?php
$con = mysql_connect ("localhost","root","nasi") or die
('cannot connect to database error: '.mysql_error());
if (isset($_POST['desk_user']) &&
isset($_POST['desk_report']) &&
isset($_POST['desk_action']))
{
$desk_user = $_POST['desk_user'];
$desk_report = $_POST['desk_report'];
$desk_action = $_POST['desk_action'];
if (!empty($desk_user)&& !empty($desk_report)&& !empty($desk_action)) {
mysql_select_db("csr", $con);
$sql = "INSERT INTO `desktoplaptop` (`desk_user`,`desk_report`,`desk_action`) VALUES ('$_POST[desk_user]','$_POST[desk_report]','$_POST[desk_action]') ";
if ($sql_run = mysql_query($sql)) {
echo 'ok.';
}
else {
echo '*Sorry, we couldn\'t register you at this time. Try again later.';
}
}
}
?>