首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我需要我所有的html表行到sumit到数据库

我需要我所有的html表行到sumit到数据库
EN

Stack Overflow用户
提问于 2013-04-01 23:36:16
回答 1查看 256关注 0票数 0

当我提交时,我想提交所有行。目前只有一行正在提交。这是我发布到数据库的方式:

代码语言:javascript
复制
<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "pro_forms_in_form")) {
  $insertSQL = sprintf("INSERT INTO ho_add_stock_proforma (supplier, inv_no, `day`, `month`, `year`, product_name, descrpt, qty, cost, hawker, wholesale, retail, total) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
  GetSQLValueString($_POST['supplier'], "text"),
  GetSQLValueString($_POST['inv_no'], "int"),
  GetSQLValueString($_POST['day'], "int"),
  GetSQLValueString($_POST['month'], "int"),
  GetSQLValueString($_POST['year'], "int"),
  GetSQLValueString($_POST['product_name'], "text"),
  GetSQLValueString($_POST['descrpt'], "text"),
  GetSQLValueString($_POST['qty'], "text"),
  GetSQLValueString($_POST['cost'], "text"),
  GetSQLValueString($_POST['hawker'], "text"),
  GetSQLValueString($_POST['wholesale'], "text"),
  GetSQLValueString($_POST['retail'], "text"),
  GetSQLValueString($_POST['total'], "text"));
  mysql_select_db($database_universal, $universal);
  $Result1 = mysql_query($insertSQL, $universal) or die(mysql_error());
}

mysql_select_db($database_universal, $universal);
$query_Creditors = "SELECT company_name FROM ho_add_creditors";
$Creditors = mysql_query($query_Creditors, $universal) or die(mysql_error());
$row_Creditors = mysql_fetch_assoc($Creditors);
$totalRows_Creditors = mysql_num_rows($Creditors);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<!-- and this part help with adding more table rows -->

<script type="text/javascript">
function addRow(ho_add_stock_proforma) {            
  var table = document.getElementById(ho_add_stock_proforma);            
  var rowCount = table.rows.length;           
  var row = table.insertRow(rowCount);            
  var colCount = table.rows[0].cells.length;            
  for(var i=0; i<colCount; i++) {                 
    var newcell = row.insertCell(i);                 
    newcell.innerHTML = table.rows[0].cells[i].innerHTML;                
    //alert(newcell.childNodes);                
    switch(newcell.childNodes[0].type) {                    
      case "text":                            
        newcell.childNodes[0].value = "";                           
        break;                    
      case "checkbox":                            
        newcell.childNodes[0].checked = false;                           
        break;                   
      case "select-one":                            
        newcell.childNodes[0].selectedIndex = 0;                           
        break;               
    }           
  }       
}        
function deleteRow(ho_add_stock_proforma) {           
  try {            
    var table = document.getElementById(ho_add_stock_proforma);           
    var rowCount = table.rows.length;             
    for(var i=0; i<rowCount; i++) {               
      var row = table.rows[i];               
      var chkbox = row.cells[0].childNodes[0];               
      if(null != chkbox && true == chkbox.checked) {                   
        if(rowCount <= 1) {                       
          alert("Cannot delete all the rows.");                       
          break;                   
        }                    
        table.deleteRow(i);                    
        rowCount--;                   
        i--;               
      }              
    }            
  }catch(e) 
  {               
    alert(e);           
  } 
  getValues();
}        

</script>
</head>
<body>

  <div id="wrap">
  <form action="<?php echo $editFormAction; ?>" method="POST" name="pro_forms_in_form">

    <!-- and this is my html table -->

    <table width="666" border="0" cellpadding="2" cellspacing="2" class="table" id="ho_add_stock_proforma" name="ho_add_stock_proforma">
    <tr>
      <td><input type="checkbox" name="chk" style="width:40px" /></td>


      <td width="122" scope="col">Product Name<input name="product_name" type="text" class="table_fields" id="product_name" /></td>
      <td width="122" scope="col">Description<input name="descrpt" type="text" class="table_fields" id="description" /></td>
      <td width="62" scope="col">Qty<input name="qty" type="text" class="qty" id="qty" onkeyup="getValues()" /></td>
      <td width="62" scope="col">Cost per Piece<input name="cost" type="text" class="price" id="cost" onkeyup="getValues()"/></td>
      <td width="62" scope="col">hawker<input name="hawker" type="text" class="price" id="hawker" /></td>
      <td width="62" scope="col">Wholesale<input name="wholesale" type="text" class="price" id="wholesale" /></td>
      <td width="62" scope="col">Retail<input name="retail" type="text" class="price" id="retail" /></td>
      <td width="349" scope="col">Total<input name="total" type="text" class="price" id="total" onKeyUp="getValues()" /></td>
      <td width="5">  <input name="button" type="button" value="Add" onclick="addRow('ho_add_stock_proforma')" style="width:40px"/></td>
      <td><input name="button"   type="button" value="Delete" onclick="deleteRow('ho_add_stock_proforma')" style="width:40px"/></td>
    </tr>
  </table>

  <input name="submit" type="submit" class="button_submit" value="Submit Form" id="submit" />

  <input type="hidden" name="MM_insert" value="pro_forms_in_form" />
  </form>
  </div>
</body>
</html>
EN

回答 1

Stack Overflow用户

发布于 2013-04-01 23:47:33

您正在通过Javascript向HTML表添加行,然后使用PHP在数据库中添加/更新行,对吗?

新的HTML表行只存在于浏览器中(您是通过Javascript在客户端创建它们的):服务器上运行的PHP不知道它们的存在,因此不能在数据库中插入/更新它们。

您将需要在服务器端生成HTML表的新行并重新加载浏览器页面,否则,如果您在客户端生成新行,则需要在每个帖子中手动包含这些新行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15746449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档