Php 提交按钮在第二次函数调用后停止工作
/*编辑*/更改了提交编辑和提交传输按钮的id,因为id重复 我正在编写一个脚本,它从MySQL数据中绘制一个表,并让用户能够编辑/删除/传输所述数据。在初始页面加载时,一切正常。但是,当我选择一个新表时,传输和编辑按钮停止工作。即使选择传出表(最初加载的表),情况也是如此。所以,问题发生在页面重新加载后的某个地方,我只是不知道在哪里。除了传输和编辑按钮外,每个按钮都可以工作 这里有一个脚本的屏幕盖,这样你就可以知道我想做什么 这是我的代码:Php 提交按钮在第二次函数调用后停止工作,php,jquery,Php,Jquery,/*编辑*/更改了提交编辑和提交传输按钮的id,因为id重复 我正在编写一个脚本,它从MySQL数据中绘制一个表,并让用户能够编辑/删除/传输所述数据。在初始页面加载时,一切正常。但是,当我选择一个新表时,传输和编辑按钮停止工作。即使选择传出表(最初加载的表),情况也是如此。所以,问题发生在页面重新加载后的某个地方,我只是不知道在哪里。除了传输和编辑按钮外,每个按钮都可以工作 这里有一个脚本的屏幕盖,这样你就可以知道我想做什么 这是我的代码: <?php require("IRCinve
<?php
require("IRCinventoryfunctions.php");
require_once 'IRCinventoryconfig.php';
$aTable = file_get_contents('php://input');
$aTable = substr($aTable, 6);
$connection = new mysqli($db_hostname, $db_username, $db_password, $db_database, $db_port);
if ($connection->connect_error) die($connection->connect_error);
global $connection;
$result = $connection->query("SHOW TABLES");
$table = array();
while ($row = $result->fetch_row()){
$table[] = $row[0];
}
$count = count($table);
?>
<div id="content">
<?php
$thatTable = !empty($aTable) ? $aTable : "OUTGOING";
{
session_start();
$_SESSION['thatTable'] = $thatTable;
global $thatTable;
$queryColumns = "SHOW COLUMNS FROM $thatTable";
$resultColumns = $connection->query($queryColumns);
if (!$resultColumns) die ("Database access failed: " . $connection->error);
global $resultColumns;
$queryRows = "SELECT * FROM $thatTable";
$resultRows = $connection->query($queryRows);
if (!$resultRows) die ("Database access failed: " . $connection->error);
global $resultRows;
$rows = $resultRows->num_rows;
global $rows;
global $connection;
drawTable();
$connection->close();
}
?>
下面是draw table函数:
function drawTable() {
global $connection;
global $resultColumns;
global $resultRows;
global $rows;
global $columns;
global $countColumnsGlobal;
global $thatTable;
$columns = array();
while ($column = $resultColumns->fetch_row()){
$columns[] = $column[0];
}
echo "<div id=\"table\"><table class=\"CSSTableGenerator\" >\n";
$countColumns = count($columns);
$countColumnsGlobal = $countColumns;
$insertColumns = array();
for ($pointer = 1 ; $pointer < $countColumns ; ++$pointer) {
$insertColumns[] = $columns[$pointer];
}
for ($pointer = 1 ; $pointer < $countColumns ; ++$pointer) {
echo "<th scope=\"col\" bgcolor=\"#efefef\">";
echo $columns[$pointer];
echo "</th>";
}
echo "<th>ACTIONS</td>";
for ($j = 0 ; $j < $rows ; ++$j)
{
$resultRows->data_seek($j);
$row = $resultRows->fetch_array(MYSQLI_NUM);
$countRows = count($row);
echo "<tr>";
for ($pointer = 1 ; $pointer < $countRows ; ++$pointer) {
echo "<td>";
echo $row[$pointer];
echo "</td>";
}
global $I_ID;
echo "<td>";
echo "<form name=\"deleteRow\" action=\"http://localhost:8888/IRC/IRCprocessinventory.php\" method=\"POST\">";
$I_ID = $row[0];
echo "<input type=\"hidden\" value=\"delete\" name=\"delete\">";
echo "<input type=\"hidden\" value=\"$thatTable\" name=\"thatTable\">";
echo "<input type=\"hidden\" value=\"$I_ID\" name=\"I_ID\">";
echo "<input type=\"submit\" value=\"delete\">";
echo "</form>";
echo "<div id=\"edit\"><input type=\"button\" name=\"$I_ID\" value=\"edit\"></div>";
echo "<div id=\"transfer\"><input type=\"button\" name=\"$I_ID\" value=\"transfer\"></div>";
echo "</td>";
echo "</tr>";
echo "<tr id=\"$I_ID\" class=\"edit\">";
echo "<form name=\"editRow\" action=\"IRCprocessinventory.php\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"edit\">";
echo "<input type=\"hidden\" name=\"$thatTable\">";
echo "<input type=\"hidden\" value=\"$I_ID\" name=\"I_ID\">";
echo "<input type=\"hidden\" value=\"$row[1]\" name=\"$columns[1]\">";
echo "<td>$row[1]</td>";
for ($pointer = 2 ; $pointer < $countRows ; ++$pointer) {
echo "<td>";
echo "<input type=\"text\" value=\"$row[$pointer]\" name=\"$columns[$pointer]\">";
echo "</td>";
}
echo "<td><input type=\"submit\" id=\"submitEdit\" class=\"submitEdit\" name=\"$I_ID\" value=\"submit edit\"></td>";
echo "</form>";
echo "</tr>";
echo "<tr id=\"transfer\" class=\"$I_ID\">";
echo "<form name=\"transfer\" action=\"IRCprocessinventory.php\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"transfer\">";
echo "<input type=\"hidden\" name=\"$thatTable\">";
echo "<input type=\"hidden\" value=\"$I_ID\" name=\"I_ID\">";
echo "<td>Transfer to OUTGOING</td>";
echo "<td>$row[2]</td>";
echo "<td><input type=\"text\" name=\"amountTransferred\"></td>";
for ($pointer = 5 ; $pointer < $countRows + 1 ; ++$pointer) {
echo "<td></td>";
}
for ($pointer = 0 ; $pointer < $countRows + 1 ; ++$pointer) {
echo "<input type=\"hidden\" name=\"$row[$pointer]\" value=\"$columns[$pointer]\">";
}
echo "<td><input type=\"submit\" id=\"submitTransfer\" class=\"submitTransfer\" name=\"$I_ID\" value=\"transfer items\"></td>";
echo "</form>";
echo "</tr>";
}
echo "</table></div>"; //end table, end content
}
函数drawTable(){
全球美元连接;
全球$resultColumns;
全球$resultRows;
全局$行;
全球$栏;
全球$countColumnsGlobal;
全球美元表;
$columns=array();
而($column=$resultColumns->fetch_row()){
$columns[]=$column[0];
}
回音“\n”;
$countColumns=计数($columns);
$countColumnsGlobal=$countColumns;
$insertColumns=array();
对于($pointer=1;$pointer<$COUNTCLUMNS;++$pointer){
$insertColumns[]=$columns[$pointer];
}
对于($pointer=1;$pointer<$COUNTCLUMNS;++$pointer){
回声“;
echo$列[$pointer];
回声“;
}
呼应“行动”;
对于($j=0;$j<$rows;++$j)
{
$resultRows->data\u seek($j);
$row=$resultRows->fetch_数组(MYSQLI_NUM);
$countRows=计数($row);
回声“;
对于($pointer=1;$pointer<$countRows;++$pointer){
回声“;
echo$row[$pointer];
回声“;
}
全球$I_ID;
回声“;
回声“;
$I_ID=$row[0];
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回显“$row[1]”;
对于($pointer=2;$pointer<$countRows;++$pointer){
回声“;
回声“;
回声“;
}
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回声“;
回显“转出”;
回显“$row[2]”;
回声“;
对于($pointer=5;$pointer<$countRows+1;++$pointer){
回声“;
}
对于($pointer=0;$pointer<$countRows+1;++$pointer){
回声“;
}
回声“;
回声“;
回声“;
}
echo”“;//结束表,结束内容
}
这是完整的脚本,如果你真的需要看的话
<!DOCTYPE html>
<script src="../_js/jquery.min.js"></script>
<script src="../_js/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
/* AJAX for table selection */
$('#values').change(function() {
var switchTable = $(this);
$.ajax({
type: 'POST',
url: "IRCdrawTables.php",
data: switchTable,
cache: false,
success: function(result){
$('#IRCdrawTables').html(result);
} //end result
}); // end ajax
return false;
}); // .change
/* jQuery for edit and transfer panels */
var editRows = document.querySelectorAll('tr.edit');
var edit = $('#edit');
$(function() {
$(editRows).hide();
});
$('input[type=button][value=edit]').on('click', function() {
var id = $(this).attr('name');
thisRow = '#' + id;
$(thisRow).fadeToggle();
});
var transferRows = document.querySelectorAll('tr#transfer');
var transfer = $('#transfer');
$(function() {
$(transferRows).hide();
});
$('input[type=button][value=transfer]').on('click', function() {
var id = $(this).attr('name');
thisRow = '.' + id;
$(thisRow).fadeToggle();
});
}); //end ready
</script>
<style>
#table {
margin-top:2px;
}
#formTable {
width:100%;
margin:0px;padding:0px;
border:1px solid #000000;
border-bottom:none;
border-left:none;
border-right:none;
}
#formTable td{
vertical-align:middle;
border:1px solid #000000;
border-width:0px 1px 1px 0px;
text-align:left;
padding:7px;
width:100px;
font-size:14px;
font-family:arial;
font-weight:normal;
color:#000000;
}
#formTable input[type="text"]{
width:95%;
}
.CSSTableGenerator {
margin:0px;padding:0px;
width:100%;
border:1px solid #000000;
border-top:none;
border-right:none;
border-left:none;
}
.CSSTableGenerator table{
width:100%;
height:100%;
margin:0px;padding:0px;
}
.CSSTableGenerator tr:nth-child(odd){ background-color:#e5e5e5; }
.CSSTableGenerator tr:nth-child(even) { background-color:#ffffff; }
.CSSTableGenerator th{
border:1px solid #000000;
border-width:0px 1px 1px 0px;
width:100px;
}
.CSSTableGenerator td{
vertical-align:middle;
border:1px solid #000000;
border-width:0px 1px 1px 0px;
text-align:left;
padding:7px;
width:100px;
font-size:14px;
font-family:arial;
font-weight:normal;
color:#000000;
}
.CSSTableGenerator tr:last-child td{
border-width:0px 1px 0px 0px;
}
.CSSTableGenerator tr td:last-child{
border-width:0px 0px 1px 0px;
}
.CSSTableGenerator tr:last-child td:last-child{
border-width:0px 0px 0px 0px;
}
.CSSTableGenerator tr:first-child td{
background:-o-linear-gradient(bottom, #cccccc 5%, #b2b2b2 100%); background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #cccccc), color-stop(1, #b2b2b2) ); background:-moz-linear-gradient( center top, #cccccc 5%, #b2b2b2 100% ); filter:progid:DXImageTransform.Microsoft.gradient(startColorstr="#cccccc", endColorstr="#b2b2b2"); background: -o-linear-gradient(top,#cccccc,b2b2b2);
background-color:#cccccc;
border:0px solid #000000;
text-align:center;
border-width:0px 0px 1px 1px;
font-size:14px;
font-family:arial;
font-weight:bold;
color:#000000;
margin-top:-2px;
}
#header {
position:absolute;
background-image: url("../_images/InventoryHeader1.jpg");
background-position:left top;
background-repeat: no-repeat;
top:0px;
left:6px;
height:163px;
width:700px;
}
#header2 {
position:absolute;
background-image: url("../_images/HeaderBar.jpg");
background-position:left top;
top:0px;
right:6px;
left:6px;
height:163px;
z-index: -1;
}
.menu {
color:black; font-size:12pt; font-family:arial,sans-serif;
font-weight:bold
}
#menu {
position:absolute;
top:174px;
left:6px;
right:6px;
height:40px;
background-color:#eceeef;
background-position:left;
border:1px solid black;
}
#menu table {
position:absolute;
top:7px;
background-color:#eceeef;
}
#menu td {
background-color:#eceeef;
}
#border {
position:absolute;
background:#ECEEEF;
left:7px;
height:3px;
width:104px;
top:438px;
z-index:4;
}
#contentHeader {
position:absolute;
height:40px;
left:325px;
right:6px;
top:230px;
background-color: #c6ccd1;
background-position:right;
border:1px solid black;
}
#content {
position:absolute;
top:270px;
left:325px;
right:6px;
bottom:95px;
background-color: #eceeef;
background-position:right;
border:1px solid black;
border-top:none;
z-index: -1;
overflow-x: auto;
}
#IRCdrawTables {
width:100%;
}
#alignSelect {
position:absolute;
width:250px;
right:0px;
top:0px;
}
#tableNameContainer {
position:absolute;
background-color:#EFEFEF;
border-right: 1px black solid;
height:40px;
text-align:center;
right:86%;
left:0px;
}
#tableName {
position:absolute;
text-align:center;
margin-top:10px;
width:100%;
z-index:1;
}
</style>
<body>
<div id="IRCdrawTables">
<?php
require("IRCinventoryfunctions.php");
require_once 'IRCinventoryconfig.php';
$aTable = file_get_contents('php://input');
$aTable = substr($aTable, 6);
$connection = new mysqli($db_hostname, $db_username, $db_password, $db_database, $db_port);
if ($connection->connect_error) die($connection->connect_error);
global $connection;
$result = $connection->query("SHOW TABLES");
$table = array();
while ($row = $result->fetch_row()){
$table[] = $row[0];
}
$count = count($table);
?>
<div id="content">
<?php
$thatTable = !empty($aTable) ? $aTable : "OUTGOING";
{
session_start();
$_SESSION['thatTable'] = $thatTable;
global $thatTable;
$queryColumns = "SHOW COLUMNS FROM $thatTable";
$resultColumns = $connection->query($queryColumns);
if (!$resultColumns) die ("Database access failed: " . $connection->error);
global $resultColumns;
$queryRows = "SELECT * FROM $thatTable";
$resultRows = $connection->query($queryRows);
if (!$resultRows) die ("Database access failed: " . $connection->error);
global $resultRows;
$rows = $resultRows->num_rows;
global $rows;
global $connection;
drawTable();
$connection->close();
}
?>
</div> <!-- End #content -->
<!-- Dropdown Menu for Table Selection -->
<div id="contentHeader">
<div id="tableNameContainer">
<div id="tableName">
<?php
session_start();
echo "<b>" . $_SESSION['thatTable'] . "</b>";
?>
</div>
</div>
<div id="tableName"></div>
<div id="alignSelect">
<div id="select">
<form name="selectTable" action="" method="POST">
<select id="values" name="value">
<option value="">--Select Table--</option>
<?php for ($pointer = 0 ; $pointer < $count ; ++$pointer) {
echo <<<_END
<pre>
<option value="$table[$pointer]">$table[$pointer]</option>
</pre>
_END;
}
?>
</select>
</form>
</div> <!-- End .select -->
<div id="deleteSelect">
<form name="deleteTable" action="IRCprocessinventory.php" method="POST">
<select id="deleteTable" name="deleteTable">
<option value="">--Delete Table--</option>
<?php for ($pointer = 0 ; $pointer < $count ; ++$pointer) {
echo <<<_END
<pre>
<option value="$table[$pointer]">$table[$pointer]</option>
</pre>
_END;
}
?>
</select>
<input type="submit" value="delete table">
</form>
</div> <!-- End deleteSelect -->
</div> <!-- End alignSelect -->
</div> <!-- End #contentHeader -->
</div> <!-- End #IRCaddTables -->
</body>
</html>
$(文档).ready(函数(){
/*用于表选择的AJAX*/
$('#values')。更改(函数(){
var switchTable=$(此);
$.ajax({
键入:“POST”,
url:“ircdawtables.php”,
数据:开关表,
cache:false,
成功:功能(结果){
$('#ircdawtables').html(结果);
}//最终结果
});//结束ajax
返回false;
})改变
/*用于编辑和传输面板的jQuery*/
var editRows=document.querySelectorAll('tr.edit');
变量编辑=$(“#编辑”);
$(函数(){
$(editRows.hide();
});
$('input[type=button][value=edit]')。在('click',function()上{
var id=$(this.attr('name');
thisRow='#'+id;
$(thisRow.fadeToggle();
});
var transferRows=document.querySelectorAll('tr#transfer');
var转移=$(“#转移”);
$(函数(){
$(transferRows.hide();
});
$('input[type=button][value=transfer]')。在('click',function()上{
var id=$(this.attr('name');
thisRow='.'+id;
$(thisRow.fadeToggle();
});
}); //准备就绪
#桌子{
边缘顶部:2倍;
}
#可成形{
宽度:100%;
边距:0px;填充:0px;
边框:1px实心#000000;
边框底部:无;
左边界:无;
边界权:无;
}
#表格td{
垂直对齐:中间对齐;
边框:1px实心#000000;
边框宽度:0px 1px 0px;
文本对齐:左对齐;
填充:7px;
宽度:100px;
字体大小:14px;
字体系列:arial;
字体大小:正常;
颜色:#000000;
}
#formTable输入[type=“text”]{
宽度:95%;
}
.CSSTableGenerator{
边距:0px;填充:0px;
宽度:100%;
边框:1px实心#000000;
边界顶部:无;
边界权:无;
左边界:无;
}
.CSSTableGenerator表{
宽度:100%;
身高:100%;
边距:0px;填充:0px;
}
.CSSTableGenerator tr:n子(奇数){背景色:#e5;}
.CSSTableGenerator tr:n子级(偶数){背景色:#ffffff;}
.CSSTableGenerator th{
边框:1px实心#000000;
边框宽度:0px 1px 0px;
宽度:100px;
}
.CSSTableGenerator td{
垂直对齐:中间对齐;
边框:1px实心#000000;
边框宽度:0px 1px 0px;
文本对齐:左对齐;
填充:7px;
宽度:100px;
字体大小:14px;
字体系列:arial;
字体大小:正常;
颜色:#000000;
}
.CSSTableGenerator tr:最后一个子项td{
边框宽度:0px 1px 0px 0px;
}
.CSSTableGenerator tr td:最后一个孩子{
边框宽度:0px 0px 1px 0px;
}
.CSSTableGenerator tr:last child td:last child{
边框宽度:0px 0px 0px 0px;
}
.CSSTableGenerator tr:第一个孩子td{
背景:-o-线性渐变(底部,#cccccc 5%,#b2b2b2 100%);背景:-webkit渐变(线性,左上,左下,颜色停止(0.05,#cccccc),颜色停止(1,#b2b2b2));背景:-moz线性渐变(中心顶部,#CCCC 5%,#b2b2b2 100%);