我有两个PHP页面
1. sup_select.php
- 这是用户必须为一个项目选择多个供应商的地方
2. suppliers.php
- 包含所有供应商详细信息。用户应该能够选择多个复选框,并且当用户单击提交时,复选框值必须传递到sup_select.php
中的文本框。
这是我的代码。
sup_select.php
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$nic = $_SESSION['nic'];
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Add Supplier</title>
<style type="text/css">
.supadd {
}
</style>
</head>
<body>
<div class="supadd">
<table width="1260" border="1">
<tr align="center">
<th width="126" scope="col">Request No.</th>
<th width="130" scope="col">Request Date</th>
<th width="87" scope="col">Item</th>
<th width="127" scope="col">Item Category</th>
<th width="168" scope="col">Requested Quantity</th>
<th width="132" scope="col">Change Quantity</th>
<th width="89" scope="col">Deliver Before</th>
<th width="101" scope="col">Suppliers</th>
<th width="90" scope="col">Forward</th>
<th width="146" scope="col">Review Request</th>
</tr>
<?php
$result = mysql_query("SELECT * FROM ops_order_request_tbl ORDER BY request_number ASC");
while($row = mysql_fetch_array($result))
{
echo "<tr align='center'>";
echo "<td>".$row['request_number']."</td>";
echo "<td>".$row['request_date']."</td>";
echo "<td>".$row['item']."</td>";
echo "<td>".$row['item_cat']."</td>";
echo "<td>".$row['requested_quantity']."</td>";
echo "<td><input type='text'></td>";
echo "<td>".$row['deliver_before']."</td>";
echo "<td><form name='' method='get' action=''>
<input name='".$row['request_number']."' type='text' value='".$checked."'><br><a href='suppliers.php'>Add Suppliers</a></form></td>";
echo "<td><form name='' method='' action=''><input type='button' value='Forward'></form></td>";
echo "<td><form name='' method='' action=''><input type='button' value='Review'></form></td>";
echo "</tr>";
}
?>
</table>
</div>
</body>
</html>
supplier.php
/ Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$nic = $_SESSION['nic'];
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Suppliers</title>
</head>
<body>
<?php
echo "<div class='supadd'>";
echo "<table border='1'>";
echo "<tr align='center'>";
echo "<th width='126' scope='col'>Supplier Name</th>";
echo "<th width='130' scope='col'>Supplier Address</th>";
echo "<th width='87' scope='col'>Contact Person</th>";
echo "<th width='127' scope='col'>Telephone</th>";
echo "<th width='168' scope='col'>Fax</th>";
echo "<th width='132' scope='col'>Email</th>";
echo "<th width='89' scope='col'> </th>";
echo "</tr>";
$result = mysql_query("SELECT * FROM ops_supplier_tbl ORDER BY name ASC");
while($row = mysql_fetch_array($result))
{
echo "<tr align='center'>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['address']."</td>";
echo "<td>".$row['contact_person']."</td>";
echo "<td>".$row['telephone']."</td>";
echo "<td>".$row['fax']."</td>";
echo "<td>".$row['email']."</td>";
echo "<td><form name='' method='post' action='sup_select.php'><input name='supcheck[]' type='checkbox' value='".$row['name']."'></td>";
echo "</tr>";
}
if(isset($_POST["supcheck"]))
{
$checked = $_POST["supcheck"];
}
else
{
$checked=array();
}
for ($i="0"; $i<count($checked); $i++)
{
if(!is_numeric($checked[$i]))
{
$checked[$i]='';
}
if(empty($checked[$i]))
{
unset($checked[$i]);
}
}
$checked=implode('<>',$checked);
echo "<input type='text' name='textfield' id='textfield' value='".$checked."'>";
echo "</table>";
echo "<input align='left' type='submit'></form>";
echo "</form>";
echo "</div>";
?>
</body>
</html>
我甚至尝试在同一页面上进行此操作,但它也不起作用。
答案 0 :(得分:0)
所有supcheck[]
应该是内部相同<form>
。
supplier.php
<form action='sup_select.php'>
<table>
...
<input name='supcheck[]' type='checkbox' value='".$row['name']."'>
...
</table>
</form>
您可以使用以下方法在PHP中访问POST数据:
<?php var_dump($_POST['supcheck']); ?>
如果您需要在<TD>
中指定<table>
的按钮,则可以使用带有Javascript OnClick功能的按钮来触发另一个外部表单。
...
<td><input type='button' onclick='gotoReview(<? echo $supplier_id; ?>)' value='Review'></td>
...
<script>
function gotoReview(id){
location.href = 'supply_review.php?id=' + id;
}
</script>