包含行id的editform和echo


include editform and echo for row id

我想做的是验证一个覆盖窗口内的编辑表单。一切都很好,直到我把表单内的popin。

我可以将行添加到数据库(在popin中有效),然后编辑现有的记录,只要表单在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>&nbsp;&nbsp;&nbsp;<a href="editmenu/export.php">Export table to xls</a>&nbsp;&nbsp;<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>

你不能那样使用…include函数需要一个路径,你需要url包装器来使用它,但我不认为它会帮助你。

http://php.net/manual/en/wrappers.php

相反,你可以这样做:

$_GET['id'] = $row['id'];
include "editform.php";

现在你可以在editform。php中使用$_GET['id']

这只是PHP代码,所以您可以使用该变量并将其连接到文件名:

<?php include "editform.php?id=" . $row['id']; ?>