我尝试做的是在叠加窗口内验证编辑表单。这一切都很好,直到我把表格放在popin中。
我可以将行添加到dbase(在popin中进行vaildated),然后编辑现有记录,只要该表单未在popin中验证。
我使用include来显示popin中的表单。
问题是我如何回应php include中的行id?
它应该是这样的想法吗?当然它不起作用。
<?php include "editform.php?id=<?php echo $row['id']"; ?>
什么是正确的语法或我应该尝试不同的方法?
页面的完整代码是:
<?php
$con = mysql_connect("localhost", "root", "****");
if (!$con) {
die("Error: " . mysql_error());
}
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM table_3");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<script type="text/javascript" charset="utf-8" src="/tables/media/js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="/tables/media/js/jquery.dataTables.js"></script>
<style type="text/css">
@import "/tables/media/css/demo_table_jui.css";
</style>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#example').dataTable({
"sPaginationType":"full_numbers",
"aaSorting":[[0, "asc"]],
"bJQueryUI":true
});
} );
</script>
</head>
<body>
<div>
<p><a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">Add new row</a> <a href="editmenu/export.php">Export table to xls</a> <a href = "javascript:void(0)" onclick = "document.getElementById('light3').style.display='block';document.getElementById('fade3').style.display='block'">Import csv </a></p>
<div id="light" class="white_content">Add a single row to a database<a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'">Close</a>
<?php include "insertform.html"; ?></div>
<div id="fade" class="black_overlay"></div>
<div id="light3" class="white_content">Import data from csv file<a href = "javascript:void(0)" onclick = "document.getElementById('light3').style.display='none';document.getElementById('fade3').style.display='none'">Close</a>
<?php include "editmenu/importcsv.php"; ?></div>
<div id="fade3" class="black_overlay"></div>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th>Id</th>
<th>Owner</th>
<th>Computer Name</th>
<th>Model</th>
<th>Serial Number</th>
<th>Machine Type</th>
<th>CG-ITO</th>
<th>Additional Info</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_array($result)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['Owner']; ?></td>
<td><?php echo $row['Computer_Name']; ?></td>
<td><?php echo $row['Model']; ?></td>
<td><?php echo $row['Serial_Number']; ?></td>
<td><?php echo $row['Machine_Type']; ?></td>
<td><?php echo $row['CG_ITO']; ?></td>
<td><?php echo $row['Additional_Info']; ?></td>
<td><a class="edit" href = "javascript:void(0)" onclick = "document.getElementById('light1').style.display='block';document.getElementById('fade1').style.display='block'">Edit</a></td>
<td><a href = "javascript:void(0)" onclick = "document.getElementById('light2').style.display='block';document.getElementById('fade2').style.display='block'">Delete</a></td>
</tr>
<?php
}
;?>
</tbody>
</table>
</div>
<div id="light1" class="white_content">Edit single row<a href = "javascript:void(0)" onclick = "document.getElementById('light1').style.display='none';document.getElementById('fade1').style.display='none'">Close</a>
<?php include "editform.php?id=" . $row['id']; ?></div>
<div id="fade1" class="black_overlay"></div>
<div id="light2" class="white_content">Delete single row<a href = "javascript:void(0)" onclick = "document.getElementById('light2').style.display='none';document.getElementById('fade2').style.display='none'">Close</a>
<?php include "deleteval.php"; ?></div>
<div id="fade2" class="black_overlay"></div>
</body>
</html>
答案 0 :(得分:0)
你不能那样使用它... include函数需要一个路径,你需要使用url包装器才能使用它,但我不认为它对你有多大帮助。
http://php.net/manual/en/wrappers.php
相反,你可以这样做:
$_GET['id'] = $row['id'];
include "editform.php";
现在您可以在该editform.php中使用$_GET['id']
答案 1 :(得分:-1)
它只是php代码,因此您可以使用该变量并将其连接到文件名:
<?php include "editform.php?id=" . $row['id']; ?>