php - 为什么我的提交按钮在我用 PHP 制作的这个表单上不起作用?
问题描述
这个真的难倒我,它是为了一些应该相对简单的东西。我正在尝试在表格中间制作一个只有提交按钮的表单,我在 PHP 中回显。此表单中提交按钮的名称是从我有工作连接的数据库中提取的。
我已经彻底测试并且可以确认数据来自数据库。我有几个其他类似的表单在页面中运行良好,并且它们运行正常。当我把这个特殊的表格放在那些工作的表格旁边时,它工作得很好。除此之外,我无法让这个表格在其他任何地方工作。
这是我损坏的表单的代码以及上下文:
function buildTables($thecategory = "staff")
{
include "db.php";
setlocale(LC_MONETARY, 'en_GB');
$stmt = $mysql->query($_SESSION['query']);
$customercount = 0;
$totalpoints = 0;
$paythismonth = 0;
while ($row = $stmt->fetch())
{
echo'<table><tr><article style="line-height: 0.5em; padding-bottom:2em; background-color:FF7070; color: white; height: 20em; width: 100em; margin-left: 14em">
<div style="display: table-row; color: white">
<div style="display: table-cell; padding-left: 2em; padding-top: 2em">
<p style="font-weight: bold; font-size: 1.8em">'.$row['Forename'].' '.$row['Surname'].'</p>
<p>ID: '.$row['ID'].'</p>
<p>Forename: '.$row['Forename'].'</p>
<p>Surname: '.$row['Surname'].'</p>';
if ($thecategory == "staff")
{
echo '</div><div style="display: table-cell; padding-left: 20em; padding-top: 2em"><br><br><p style="font-weight: bold; font-size: 1.2em">Emergency Contact</p>
<p>Forename: '.$row['Emergency Forename'].'</p>
<p>Surname : '.$row['Emergency Surname'].'</p>
<p>Address Line 1 : '.$row['Emergency Address Line 1'].'</p>
<p>Address Line 2 : '.$row['Emergency Address Line 2'].'</p>
<p>City: '.$row['Emergency City'].'</p>
<p>Country: '.$row['Emergency Country'].'</p>
<p>Postcode: '.$row['Emergency Postcode'].'</p>
#BROKEN FORM HERE
<form action="editstaff.php" method="post">
<input type="submit" value="Edit staff member" style="font-size: 1.2em" name="'.$row['ID'].'" /></form></div>';
}
这是我桌子上其他地方可以让表格工作的地方。
if ($thecategory == "customers")
{
$customercount+=1;
echo '</div><div style="display: table-cell; padding-left: 20em; padding-top: 2em"><br><br>
<p>Points: '.$row['Points'].'</p>';
$totalpoints += $row['Points'];
$averagepoints = $totalpoints / $customercount;
echo '
<form action="editcustomer.php" method="post">
<input type="submit" value="Edit customer" style="font-size: 1.2em" name="'.$row['ID'].'"></form>
<form action="removecustomer.php" method="post">
<input type="submit" value="Remove customer" style="font-size: 1.2em" name="'.$row['ID'].'"></form></div>';
}
只是为了确认一下,这种确切的代码在我网站的其他地方完全可以正常工作,但在这里却不行。有任何想法吗?
编辑:这是页面的整个 HTML 输出:
<head>
<title>Manager</title>
<link rel="stylesheet" type="text/css" href="gamerz-Music.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<font face="Arial Black", Gadget, sans-serif></font>
</head>
<style>
body {
background-image: url("blank.png")
}
</style>
<div class="header">
<img src="logo.png" alt="">
<div class="topnav">
<a class="active" href="#Home">Home</a>
<a href="/2018-ac32006/team7/games.php">Games</a>
<a href="/2018-ac32006/team7/music.php">Music</a>
<a href="/2018-ac32006/team7/tvandmovies.php">TV/FILM</a>
<div class="search-container">
<form action="/action_page.php">
<input type="text" placeholder="Search.." name="search">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
</div>
<br><br><br>
<div class="Pop" style="width: 1em; position: fixed; margin-top: 4em">
<form method = "post">
<input type="submit" name="staff" value="View all staff" style="font-size: 1.2em; background-color: pink; height: 3em; width: 10em">
<input type="submit" name="customers" value="View all customers" style="font-size: 1.2em; background-color: pink; height: 3em; width: 10em; margin-top: 1em">
<form>
</div>
<br>CATEGORY = staff<br><table><tr><article style="line-height: 0.5em; padding-bottom:2em; background-color:FF7070; color: white; height: 20em; width: 100em; margin-left: 14em">
<div style="display: table-row; color: white">
<div style="display: table-cell; padding-left: 2em; padding-top: 2em">
<p style="font-weight: bold; font-size: 1.8em">William Shatner</p>
<p>ID: DI3446</p>
<p>Forename: William</p>
<p>Surname: Shatner</p><p>Role: Technician</p>
<p>Date of Birth: 1931-03-22</p>
<p>Date Employed: 2015-02-04</p>
<p>NI Number: OO502044N</p>
<p>Hourly Salary: £10.20</p>
<p>Hours This Month: 40</p><p>Pay so far this month: £408.00</p>
<p>Contact Number: 07987345197</p></div><div style="display: table-cell; padding-left: 20em; padding-top: 2em"><br><br><p style="font-weight: bold; font-size: 1.2em">Contact Details</p>
<p>Address Line 1 : 48 Victoria Road</p>
<p>Address Line 2 : </p>
<p>City : Bath</p>
<p>Country: UK</p>
<p>Postcode: BA56 2SY</p></div><div style="display: table-cell; padding-left: 20em; padding-top: 2em"><br><br><p style="font-weight: bold; font-size: 1.2em">Emergency Contact</p>
<p>Forename: Leonard</p>
<p>Surname : Nimoy</p>
<p>Address Line 1 : 98 East Street</p>
<p>Address Line 2 : </p>
<p>City: Cambridge</p>
<p>Country: UK</p>
<p>Postcode: CM6 0WT</p>
<form method="POST" action="editstaff.php">
<input type="hidden" name="ID" value="DI3446">
<input type="submit" name="submit" value="submit"></form></div></article></tr></table><br>
</body>
<div class="footer">
<a href="Sam">Facebook Page</a>
<br>
<a href="Location"> Dundee DD1 4LA</a>
</div>
解决方案
问题很简单。为了提交表单,您必须将按钮放在<form></form>
标签之间,如下所示:
<form method="POST" action="your_file.php">
<input type="hidden" name="ID" value=".$row['ID'].">
<input type="submit" name="submit" value="submit">
</form>
更好的方法是放置一个标签,如:
<a href="your_file.php?ID=".$row['ID']."&action=edit">edit</a>
<a href="your_file.php?ID=".$row['ID']."&action=remove">remove</a>
推荐阅读
- google-chrome - 使用 getDisplayMedia 尝试从 Puppeteer 中的 Chrome 选项卡记录屏幕时,Google Chrome 无头错误“不支持”
- html - 如何从 owl-date-time 组件中删除月份和日期名称?
- azure - Azure 应用程序网关运行状况探测状态代码
- php - 根据存储路径显示文件夹中的图像
- flutter - 禁止flutter_plugin_pdf_viewer >=1.0.4
- ios - 如何设置 UIViewRepresentable 的大小?
- python - 如何修复 Keras.NET BadImageFormatException 异常?
- sql-server - 选择查询优于 IN 查询的 SQL 查询优化
- laravel - Laravel 收集过滤器
- amazon-web-services - ansible 和 aws cloudwatch 日志组的retentionInDays 错误