0

我正在使用 PHP 处理 JQuery 编辑表。我通过表格发布表格名称以显示表格并进行实时修改。我的问题是将表名变量重新传递给第二个 php 文件(live_edit.php)以执行修改。

Form.html ($_POST["tablename"]) => =>jedit.php => (live_edit.php, custom_edit_table.js)

我的form.html

<form action="jedit.php" method="POST">
<input type="text" name="tablename" id="tablename"/>
<input type="submit" id="upload" name="upload" value="Submit"/>
</form>

jedit.php:

<html>
<head>
<title>Jquery Edit table</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery-tabledit-1.2.3/jquery.tabledit.js"></script>
<script type="text/javascript" src="custom_table_edit.js"></script>
</head>
<body>
<table id="data_table" class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Coding</th>

</tr>
</thead>
<tbody>
<?php
require_once 'config.php';
$tablename=mysqli_real_escape_string($conn,$_POST['$tablename']);
$sql_query = 'SELECT id,Coding FROM '.$tablename.' LIMIT 10';
$resultset = mysqli_query($conn, $sql_query) or die("database error:". mysqli_error($conn));
while( $developer = mysqli_fetch_assoc($resultset) ) {
?>
<tr id="<?php echo $developer ['id']; ?>">
<td><?php echo $developer ['id']; ?></td>
<td><?php echo $developer ['Coding']; ?></td>

</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>

live_edit.php:

<?php
include_once("config.php");
$tablename=mysqli_real_escape_string($conn,$_POST['tablename']);
$input = filter_input_array(INPUT_POST);
if ($input['action'] == 'edit') {
$update_field='';
if(isset($input['Coding'])) {
$update_field.= "Coding='".$input['Coding']."'";
} 
if($update_field && $input['id']) {
$sql_query = "UPDATE ".$tablename." SET $update_field WHERE id='" . $input['id'] . "'";
mysqli_query($conn, $sql_query) or die("database error:". mysqli_error($conn));
}
}
?>

custom_edit_table.js:

$(document).ready(function(){
$('#data_table').Tabledit({
deleteButton: false,
editButton: false,
columns: {
identifier: [0, 'id'],
editable: [[1, 'Coding']]
},
hideIdentifier: true,
url: 'live_edit.php'
});
});
4

0 回答 0