我要做的是从表中恢复数据并动态添加到表中供用户编辑。事情是,当用户单击Προσθηκη以添加带有addRow函数的新空字段时,我无法找到方法。
<?php
session_start();
if (!isset($_SESSION['manager'])) {
header("location: admin_login.php");
exit();
}
$managerID= preg_replace('#[^0-9]#i','', $_SESSION["id"]);
$manager= preg_replace('#[^A-Za-z0-9]#i','', $_SESSION["manager"]);
$password= preg_replace('#[^A-Za-z0-9]#i','', $_SESSION["password"]);
include "../storescripts/connect_to_mysql.php";
$sql=mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1");
$existCount=mysql_num_rows($sql);
if($existCount==0){
echo "Your Log In session data is not on record in the database";
exit();
}
&GT;
<?php
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['product_name'])) {
$pid = mysql_real_escape_string($_POST['thisID']);
$product_name = mysql_real_escape_string($_POST['product_name']);
$price = mysql_real_escape_string($_POST['price']);
$category = mysql_real_escape_string($_POST['category']);
$subcategory = mysql_real_escape_string($_POST['subcategory']);
$details = mysql_real_escape_string($_POST['details']);
// See if that product name is an identical match to another product in the system
$sql = mysql_query("UPDATE products SET product_name='$product_name', price='$price', details='$details', category='$category', subcategory='$subcategory' WHERE id='$pid'");
if($_FILES['my_photo']['tmp_name'] != ""){
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['my_photo']['tmp_name'], "../inventory_images/$newname");
}
header("location: inventory_list.php");
exit();
}
?>
<?php
//Edit Product Block
if (isset($_GET['pid'])) {
$targetID=$_GET['pid'];
$sql=mysql_query("SELECT * FROM products WHERE id='$targetID' LIMIT 1");
$product_count=mysql_num_rows($sql);
if($product_count > 0){
while($row = mysql_fetch_array($sql)){
$product_name=$row["product_name"];
//Condition
$condition_t=$row["active"];
if($condition_t == 1){
$condition="<tr>
<td>Κατάσταση</td>
<td>
<label>
<input type='radio' name='condition' value='1' checked='checked'> Ενεργό</input>
<input type='radio' name='condition' value='0'> Ανενεργό</input>
</label>
</td>
</tr>";
}else if($condition_t == 0){
$condition="<tr>
<td>Κατάσταση</td>
<td>
<label>
<input type='radio' name='condition' value='1'> Ενεργό</input>
<input type='radio' name='condition' value='0' checked='checked'> Ανενεργό</input>
</label>
</td>
</tr>";
}
$price=$row["price"];
//Supplier
$supplier=$row["supplier"];
$sql_2=mysql_query("SELECT id,name FROM suppliers ORDER BY id");
$suppliers_list = "<select name='supplier_choice'>
<option value='0'>-------</option>";
while($row_2 = mysql_fetch_array($sql_2)){
$suppliers_id=$row_2["id"];
$suppliers_name=$row_2["name"];
if($suppliers_id == $supplier){
$suppliers_list .= "<option value='$suppliers_id' selected='selected'>$suppliers_name</option>";
}else{
$suppliers_list .= "<option value='$suppliers_id'>$suppliers_name</option>";
}
}
$suppliers_list .="</select>";
//Category
$category=$row["category"];
$category_list = "<select name='category_choice'><option value='0'> -----------</option>";
$sql_3=mysql_query("SELECT id,category_name FROM category WHERE tier='1'");
while($row_p = mysql_fetch_array($sql_3)){
$id_p=$row_p["id"];
$category_name_p=$row_p["category_name"];
$category_list .= "<option value='$id_p' disabled='disabled'>$category_name_p</option>";
$sql_4=mysql_query("SELECT id,category_name FROM category WHERE parent='$id_p'");
while($row_c = mysql_fetch_array($sql_4)){
$id_c=$row_c["id"];
$category_name_c=$row_c["category_name"];
if($category == $id_c){
$category_list .= "<option value='$id_c' selected='selected'> $category_name_c</option>";
}else{
$category_list .= "<option value='$id_c'> $category_name_c</option>";
}
}
}
$category_list .="</select>";
$details=$row["details"];
//Info
$sql_5=mysql_query("SELECT id, add_info FROM info WHERE parent='$targetID'");
$info_count=mysql_num_rows($sql_5);
global $info_count;
$info_table ="
<tr>
<td>Τεχνικά Χαρακτηριστικά</td>";
if($info_count > 0){
$counter = 0;
while($row_8 = mysql_fetch_array($sql_5)){
if( $counter == 0){
$info_id = $row_8["id"];
$info_add = $row_8["add_info"];
$info_table .="<td><input type='text' name='information[]' id='information' size='84' value='$info_add'/></td></tr>";
$counter = $counter + 1;
}else{
$info_id = $row_8["id"];
$info_add = $row_8["add_info"];
$info_table .="<tr>
<td></td>
<td>
<input type='text' name='information[]' id='information' size='84' value='$info_add'/>
</td>
</tr>";
}/* End Else If */
}/*End While*/
}
$date_added=strftime("%b %d, %Y", strtotime($row["date_added"]));
}
}else{
echo "This product doesn't exist anymore.";
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inventory Area</title>
<link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/>
<SCRIPT language="javascript">
//Add Information
i=<?php echo $info_count ?>;
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = 7+(i-1);
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell2.innerHTML = table.rows[6].cells[1].innerHTML;
document.getElementById(information[i-1]).value="";
i++;
}
function deleteRow(tableID) {
if(i>=2){
var table = document.getElementById(tableID);
table.deleteRow(i+5);
i--;
}
}
</SCRIPT>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<div id="pageContent">
<form action="edit_product.php" enctype="multipart/form-data" name="my_Form" id="my_Form" method="post">
<h2>Επεξεργασία Προϊόντος</h2>
<table width="80%" border="0" cellspacing="0" cellpadding="6" id="dataTable">
<tr>
<td>Όνομα</td>
<td>
<label>
<input name="product_name" type="text" id="product_name" size="100" value="<?php echo $product_name ?>" />
</label>
</td>
</tr>
<?php echo $condition;?>
<tr>
<td>Τιμή</td>
<td>
<label>
<input name="price" type="text" id="price" size="20" value="<?php echo $price ?>" />
</label>
</td>
</tr>
<tr>
<td>Προμηθευτές</td>
<td>
<?php echo $suppliers_list; ?>
</td>
</tr>
<tr>
<td>Κατηγορία</td>
<td>
<?php echo $category_list; ?>
</td>
</tr>
<tr>
<td>Περιγραφή</td>
<td>
<label>
<textarea name="details" id="details" cols="64" rows="5"><?php echo $details ?> </textarea>
</label>
</td>
</tr>
<?php echo $info_table ?>
<tr>
<td></td>
<td>
<INPUT type="button" value="Προσθήκη" onClick="addRow('dataTable')"/>
<INPUT type="button" value="Αφαίρεση" onClick="deleteRow('dataTable')"/>
</td>
</tr>
<tr>
<td>Εικόνα</td>
<td>
<label>
<input type="file" name="my_photo" id="my_photo"/>
</label>
</td>
</tr>
<tr>
<td> </td>
<td>
<label>
<input name="thisID" type="hidden" value="<?php echo $targetID ?>" />
<input type="submit" name="button" id="button" value="Αποθήκευση" />
</label>
</td>
</tr>
</table>
</form>
</div>
<?php include_once("../template_footer.php");?>
</div>
答案 0 :(得分:0)
JavaScript的:
function insertRow(position) {
var table = document.getElementById("theTable");
var tr = table.insertRow(position);
var td = tr.insertCell(0);
tr.insertCell(1);
tr.insertCell(2);
var textNode = document.createTextNode("\u00A0");
td.appendChild(textNode);
}
jQuery的:
function insertRow() {
$("#theTable").append("<tr><td> </td><td></td><td></td></tr>");
}